From d360aa78f7756190aac606ce543ba950a35755a7 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] TemperatureMeasurement TemperatureMeasurement --- circuitmatter/__main__.py | 7 ++++++ .../general/temperature_measurement.py | 13 ++++++++++ .../measurement/temperature_sensor.py | 25 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 circuitmatter/clusters/general/temperature_measurement.py create mode 100644 circuitmatter/device_types/measurement/temperature_sensor.py diff --git a/circuitmatter/__main__.py b/circuitmatter/__main__.py index 5ae0674..b2eebf6 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: @@ -221,6 +222,10 @@ 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") replay_device_state = pathlib.Path("test_data/replay_device_state.json") @@ -249,7 +254,9 @@ def run(replay_file=None): matter = cm.CircuitMatter(socketpool, mdns_server, random_source, device_state) led = NeoPixel("neopixel1") + tempSensor1 = TempSensor("TempSensor1") matter.add_device(led) + matter.add_device(tempSensor1) while True: matter.process_packets() diff --git a/circuitmatter/clusters/general/temperature_measurement.py b/circuitmatter/clusters/general/temperature_measurement.py new file mode 100644 index 0000000..75ebddd --- /dev/null +++ b/circuitmatter/clusters/general/temperature_measurement.py @@ -0,0 +1,13 @@ +from circuitmatter import data_model + + +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 + ) diff --git a/circuitmatter/device_types/measurement/temperature_sensor.py b/circuitmatter/device_types/measurement/temperature_sensor.py new file mode 100644 index 0000000..70c54c4 --- /dev/null +++ b/circuitmatter/device_types/measurement/temperature_sensor.py @@ -0,0 +1,25 @@ +from circuitmatter.clusters.general.identify import Identify +from circuitmatter.clusters.general.temperature_measurement import ( + TemperatureMeasurement, +) +from .. import simple_device + +import random + + +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) + + self._temp.MeasuredValue = random.randint( + 1500, 2500 + ) # Random temp between 15°C and 25°C