Skip to content

Commit

Permalink
TemperatureMeasurement
Browse files Browse the repository at this point in the history
TemperatureMeasurement
  • Loading branch information
lboue committed Oct 17, 2024
1 parent db186e6 commit d360aa7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions circuitmatter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()

Expand Down
13 changes: 13 additions & 0 deletions circuitmatter/clusters/general/temperature_measurement.py
Original file line number Diff line number Diff line change
@@ -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
)
25 changes: 25 additions & 0 deletions circuitmatter/device_types/measurement/temperature_sensor.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d360aa7

Please sign in to comment.