From 9d9ed3ce624579a7e7138a3964833768da771b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 15:31:21 +0200 Subject: [PATCH 01/13] TemperatureMeasurement cluster --- .../general/temperature_measurement.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 circuitmatter/clusters/general/temperature_measurement.py diff --git a/circuitmatter/clusters/general/temperature_measurement.py b/circuitmatter/clusters/general/temperature_measurement.py new file mode 100644 index 0000000..93823f5 --- /dev/null +++ b/circuitmatter/clusters/general/temperature_measurement.py @@ -0,0 +1,27 @@ +from circuitmatter import data_model +from circuitmatter import tlv + + +''' + static var CLUSTERS = matter.consolidate_clusters(_class, { + 0x0402: [0,1,2], # Temperature Measurement p.97 - no writable + }) + static var TYPES = { 0x0302: 2 } # Temperature Sensor, rev 2 +''' +class TemperatureMeasurement(data_model.Cluster): + CLUSTER_ID = 0x0402 + + ''' + # ==================================================================================================== + if cluster == 0x0402 # ========== Temperature Measurement 2.3 p.97 ========== + if attribute == 0x0000 # ---------- MeasuredValue / i16 (*100) ---------- + return tlv_solo.set_or_nil(TLV.I2, self.shadow_value) + elif attribute == 0x0001 # ---------- MinMeasuredValue / i16 (*100) ---------- + return tlv_solo.set(TLV.I2, -5000) # -50 °C + elif attribute == 0x0002 # ---------- MaxMeasuredValue / i16 (*100) ---------- + return tlv_solo.set(TLV.I2, 15000) # 150 °C + end + ''' + MeasuredValue = data_model.NumberAttribute(0x0000, signed=True, bits=16, default=0) + MinMeasuredValue = data_model.NumberAttribute(0x0001, signed=True, bits=16, default=-5000) + MaxMeasuredValue = data_model.NumberAttribute(0x0002, signed=True, bits=16, default=15000) From 07186824ff9cc6b306d374329a4985c39870fab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 15:46:32 +0200 Subject: [PATCH 02/13] Create temperature_sensor.py --- .../measurement/temperature_sensor.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 circuitmatter/device_types/measurement/temperature_sensor.py diff --git a/circuitmatter/device_types/measurement/temperature_sensor.py b/circuitmatter/device_types/measurement/temperature_sensor.py new file mode 100644 index 0000000..7c85a3f --- /dev/null +++ b/circuitmatter/device_types/measurement/temperature_sensor.py @@ -0,0 +1,19 @@ +from circuitmatter.clusters.general.identify import Identify +from circuitmatter.clusters.general.temperature_measurement import TemperatureMeasurement + +from .. import simple_device + + +class TemperatureSensor(simple_device.SimpleDevice): + DEVICE_TYPE_ID = 0x0302 + REVISION = 2 + + def __init__(self, name): + super().__init__(name) + + self._identify = Identify() + self.servers.append(self._identify) + + self._temp = TemperatureMeasurement() + self.servers.append(self._temp) + From 11592110eba9b44d2531b8eafa391fa22c4ed2d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 15:51:26 +0200 Subject: [PATCH 03/13] Update __main__.py --- circuitmatter/__main__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/circuitmatter/__main__.py b/circuitmatter/__main__.py index 5ae0674..12e6b51 100644 --- a/circuitmatter/__main__.py +++ b/circuitmatter/__main__.py @@ -12,6 +12,7 @@ import circuitmatter as cm from circuitmatter.device_types.lighting import on_off +from circuitmatter.device_types.measurement import temperature_sensor class ReplaySocket: @@ -249,7 +250,9 @@ def run(replay_file=None): matter = cm.CircuitMatter(socketpool, mdns_server, random_source, device_state) led = NeoPixel("neopixel1") + tempSensor = temperature_sensor() matter.add_device(led) + matter.add_device(tempSensor) while True: matter.process_packets() From 57b8ada1873c67e2bf67d839540a04e31bfb6940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 16:18:02 +0200 Subject: [PATCH 04/13] Update __main__.py --- circuitmatter/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/circuitmatter/__main__.py b/circuitmatter/__main__.py index 12e6b51..1738c58 100644 --- a/circuitmatter/__main__.py +++ b/circuitmatter/__main__.py @@ -250,9 +250,9 @@ def run(replay_file=None): matter = cm.CircuitMatter(socketpool, mdns_server, random_source, device_state) led = NeoPixel("neopixel1") - tempSensor = temperature_sensor() + tempSensor1 = TempS("TempSensor1") matter.add_device(led) - matter.add_device(tempSensor) + matter.add_device(tempSensor1) while True: matter.process_packets() From bf87691a7339d625837c4fbe8cccf55f277b651b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:01:22 +0200 Subject: [PATCH 05/13] Update temperature_measurement.py --- .../clusters/general/temperature_measurement.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/circuitmatter/clusters/general/temperature_measurement.py b/circuitmatter/clusters/general/temperature_measurement.py index 93823f5..7e99a8b 100644 --- a/circuitmatter/clusters/general/temperature_measurement.py +++ b/circuitmatter/clusters/general/temperature_measurement.py @@ -2,26 +2,9 @@ from circuitmatter import tlv -''' - static var CLUSTERS = matter.consolidate_clusters(_class, { - 0x0402: [0,1,2], # Temperature Measurement p.97 - no writable - }) - static var TYPES = { 0x0302: 2 } # Temperature Sensor, rev 2 -''' class TemperatureMeasurement(data_model.Cluster): CLUSTER_ID = 0x0402 - ''' - # ==================================================================================================== - if cluster == 0x0402 # ========== Temperature Measurement 2.3 p.97 ========== - if attribute == 0x0000 # ---------- MeasuredValue / i16 (*100) ---------- - return tlv_solo.set_or_nil(TLV.I2, self.shadow_value) - elif attribute == 0x0001 # ---------- MinMeasuredValue / i16 (*100) ---------- - return tlv_solo.set(TLV.I2, -5000) # -50 °C - elif attribute == 0x0002 # ---------- MaxMeasuredValue / i16 (*100) ---------- - return tlv_solo.set(TLV.I2, 15000) # 150 °C - end - ''' MeasuredValue = data_model.NumberAttribute(0x0000, signed=True, bits=16, default=0) MinMeasuredValue = data_model.NumberAttribute(0x0001, signed=True, bits=16, default=-5000) MaxMeasuredValue = data_model.NumberAttribute(0x0002, signed=True, bits=16, default=15000) From 5dfe7237a2fb80e983d1b0abb1ea9932cfaea53c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:03:54 +0200 Subject: [PATCH 06/13] Update temperature_sensor.py --- circuitmatter/device_types/measurement/temperature_sensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/circuitmatter/device_types/measurement/temperature_sensor.py b/circuitmatter/device_types/measurement/temperature_sensor.py index 7c85a3f..3bcea70 100644 --- a/circuitmatter/device_types/measurement/temperature_sensor.py +++ b/circuitmatter/device_types/measurement/temperature_sensor.py @@ -16,4 +16,6 @@ def __init__(self, name): self._temp = TemperatureMeasurement() self.servers.append(self._temp) + + self._temp.MeasuredValue = 1850 # 18.5°C * 100 From 63b32db65a34db657e3e5b0a3eb368280f36ef1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:06:31 +0200 Subject: [PATCH 07/13] Update __main__.py --- circuitmatter/__main__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/circuitmatter/__main__.py b/circuitmatter/__main__.py index 1738c58..393295b 100644 --- a/circuitmatter/__main__.py +++ b/circuitmatter/__main__.py @@ -221,6 +221,9 @@ def socket(self, *args, **kwargs): class NeoPixel(on_off.OnOffLight): pass +class TempSensor(temperature_sensor.TemperatureSensor): + pass + def run(replay_file=None): device_state = pathlib.Path("test_data/device_state.json") @@ -250,7 +253,7 @@ def run(replay_file=None): matter = cm.CircuitMatter(socketpool, mdns_server, random_source, device_state) led = NeoPixel("neopixel1") - tempSensor1 = TempS("TempSensor1") + tempSensor1 = TempSensor("TempSensor1") matter.add_device(led) matter.add_device(tempSensor1) while True: From 60c819b52092d7a205ea4a41961fd3914072bf56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:12:51 +0200 Subject: [PATCH 08/13] Update temperature_sensor.py --- circuitmatter/device_types/measurement/temperature_sensor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/circuitmatter/device_types/measurement/temperature_sensor.py b/circuitmatter/device_types/measurement/temperature_sensor.py index 3bcea70..b6fa47e 100644 --- a/circuitmatter/device_types/measurement/temperature_sensor.py +++ b/circuitmatter/device_types/measurement/temperature_sensor.py @@ -3,6 +3,8 @@ from .. import simple_device +import random + class TemperatureSensor(simple_device.SimpleDevice): DEVICE_TYPE_ID = 0x0302 From 245eef940ed79593c0ee4f5b9f0e234bcdcd3afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:14:29 +0200 Subject: [PATCH 09/13] Ruff --- .../clusters/general/temperature_measurement.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/circuitmatter/clusters/general/temperature_measurement.py b/circuitmatter/clusters/general/temperature_measurement.py index 7e99a8b..75ebddd 100644 --- a/circuitmatter/clusters/general/temperature_measurement.py +++ b/circuitmatter/clusters/general/temperature_measurement.py @@ -1,10 +1,13 @@ from circuitmatter import data_model -from circuitmatter import tlv class TemperatureMeasurement(data_model.Cluster): CLUSTER_ID = 0x0402 MeasuredValue = data_model.NumberAttribute(0x0000, signed=True, bits=16, default=0) - MinMeasuredValue = data_model.NumberAttribute(0x0001, signed=True, bits=16, default=-5000) - MaxMeasuredValue = data_model.NumberAttribute(0x0002, signed=True, bits=16, default=15000) + MinMeasuredValue = data_model.NumberAttribute( + 0x0001, signed=True, bits=16, default=-5000 + ) + MaxMeasuredValue = data_model.NumberAttribute( + 0x0002, signed=True, bits=16, default=15000 + ) From 425efa926361bd461bfe18a1ccc94c6f0f0ffdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:15:49 +0200 Subject: [PATCH 10/13] Ruff --- circuitmatter/__main__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/circuitmatter/__main__.py b/circuitmatter/__main__.py index 393295b..b2eebf6 100644 --- a/circuitmatter/__main__.py +++ b/circuitmatter/__main__.py @@ -221,6 +221,7 @@ def socket(self, *args, **kwargs): class NeoPixel(on_off.OnOffLight): pass + class TempSensor(temperature_sensor.TemperatureSensor): pass From 23d8f0f2d857dfe851a3e88462f68d2118fa445a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:21:45 +0200 Subject: [PATCH 11/13] Update temperature_sensor.py --- circuitmatter/device_types/measurement/temperature_sensor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circuitmatter/device_types/measurement/temperature_sensor.py b/circuitmatter/device_types/measurement/temperature_sensor.py index b6fa47e..6c94d4a 100644 --- a/circuitmatter/device_types/measurement/temperature_sensor.py +++ b/circuitmatter/device_types/measurement/temperature_sensor.py @@ -19,5 +19,6 @@ def __init__(self, name): self._temp = TemperatureMeasurement() self.servers.append(self._temp) - self._temp.MeasuredValue = 1850 # 18.5°C * 100 + self._temp.MeasuredValue = random.randint(1500, 2500) # Random temp between 15°C and 25°C + From 0b87b2bfe545a7eac60946771da1d1e3e7314dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:25:20 +0200 Subject: [PATCH 12/13] Ruff --- .../device_types/measurement/temperature_sensor.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/circuitmatter/device_types/measurement/temperature_sensor.py b/circuitmatter/device_types/measurement/temperature_sensor.py index 6c94d4a..8ffd28f 100644 --- a/circuitmatter/device_types/measurement/temperature_sensor.py +++ b/circuitmatter/device_types/measurement/temperature_sensor.py @@ -1,6 +1,7 @@ from circuitmatter.clusters.general.identify import Identify -from circuitmatter.clusters.general.temperature_measurement import TemperatureMeasurement - +from circuitmatter.clusters.general.temperature_measurement import ( + TemperatureMeasurement, +) from .. import simple_device import random @@ -19,6 +20,8 @@ def __init__(self, name): self._temp = TemperatureMeasurement() self.servers.append(self._temp) - self._temp.MeasuredValue = random.randint(1500, 2500) # Random temp between 15°C and 25°C + self._temp.MeasuredValue = random.randint( + 1500, 2500 + ) # Random temp between 15°C and 25°C From 45787b6efa3314bd3764ded78bab125cbbbf84ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20BOU=C3=89?= Date: Thu, 17 Oct 2024 17:27:00 +0200 Subject: [PATCH 13/13] Update temperature_sensor.py --- circuitmatter/device_types/measurement/temperature_sensor.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/circuitmatter/device_types/measurement/temperature_sensor.py b/circuitmatter/device_types/measurement/temperature_sensor.py index 8ffd28f..70c54c4 100644 --- a/circuitmatter/device_types/measurement/temperature_sensor.py +++ b/circuitmatter/device_types/measurement/temperature_sensor.py @@ -23,5 +23,3 @@ def __init__(self, name): self._temp.MeasuredValue = random.randint( 1500, 2500 ) # Random temp between 15°C and 25°C - -