Skip to content

Commit bb214f1

Browse files
Update PropertyDescriptor to ThingProperty in all examples and tests
1 parent 125092f commit bb214f1

File tree

10 files changed

+31
-32
lines changed

10 files changed

+31
-32
lines changed

docs/source/quickstart/counter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
from labthings_fastapi.thing import Thing
33
from labthings_fastapi.decorators import thing_action
4-
from labthings_fastapi.descriptors import PropertyDescriptor
4+
from labthings_fastapi.descriptors import ThingProperty
55

66

77
class TestThing(Thing):
@@ -24,7 +24,7 @@ def slowly_increase_counter(self) -> None:
2424
time.sleep(1)
2525
self.increment_counter()
2626

27-
counter = PropertyDescriptor(
27+
counter = ThingProperty(
2828
model=int, initial_value=0, readonly=True, description="A pointless counter"
2929
)
3030

examples/counter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
from labthings_fastapi.thing import Thing
33
from labthings_fastapi.decorators import thing_action
4-
from labthings_fastapi.descriptors import PropertyDescriptor
4+
from labthings_fastapi.descriptors import ThingProperty
55
from labthings_fastapi.server import ThingServer
66

77

@@ -25,7 +25,7 @@ def slowly_increase_counter(self) -> None:
2525
time.sleep(1)
2626
self.increment_counter()
2727

28-
counter = PropertyDescriptor(
28+
counter = ThingProperty(
2929
model=int, initial_value=0, readonly=True, description="A pointless counter"
3030
)
3131

examples/demo_thing_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from labthings_fastapi.thing import Thing
55
from labthings_fastapi.decorators import thing_action
66
from labthings_fastapi.server import ThingServer
7-
from labthings_fastapi.descriptors import PropertyDescriptor
7+
from labthings_fastapi.descriptors import ThingProperty
88
from pydantic import Field
99
from fastapi.responses import HTMLResponse
1010

@@ -60,11 +60,11 @@ def slowly_increase_counter(self):
6060
time.sleep(1)
6161
self.increment_counter()
6262

63-
counter = PropertyDescriptor(
63+
counter = ThingProperty(
6464
model=int, initial_value=0, readonly=True, description="A pointless counter"
6565
)
6666

67-
foo = PropertyDescriptor(
67+
foo = ThingProperty(
6868
model=str,
6969
initial_value="Example",
7070
description="A pointless string for demo purposes.",

examples/opencv_camera_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from fastapi import FastAPI
55
from fastapi.responses import HTMLResponse, StreamingResponse
6-
from labthings_fastapi.descriptors.property import PropertyDescriptor
6+
from labthings_fastapi.descriptors.property import ThingProperty
77
from labthings_fastapi.thing import Thing
88
from labthings_fastapi.decorators import thing_action, thing_property
99
from labthings_fastapi.server import ThingServer
@@ -279,7 +279,7 @@ def exposure(self, value):
279279
with self._cap_lock:
280280
self._cap.set(cv.CAP_PROP_EXPOSURE, value)
281281

282-
last_frame_index = PropertyDescriptor(int, initial_value=-1)
282+
last_frame_index = ThingProperty(int, initial_value=-1)
283283

284284
mjpeg_stream = MJPEGStreamDescriptor(ringbuffer_size=10)
285285

examples/picamera2_camera_server.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pydantic import BaseModel, BeforeValidator
66

7-
from labthings_fastapi.descriptors.property import PropertyDescriptor
7+
from labthings_fastapi.descriptors.property import ThingProperty
88
from labthings_fastapi.thing import Thing
99
from labthings_fastapi.decorators import thing_action, thing_property
1010
from labthings_fastapi.server import ThingServer
@@ -24,14 +24,12 @@
2424
logging.basicConfig(level=logging.INFO)
2525

2626

27-
class PicameraControl(PropertyDescriptor):
27+
class PicameraControl(ThingProperty):
2828
def __init__(
2929
self, control_name: str, model: type = float, description: Optional[str] = None
3030
):
3131
"""A property descriptor controlling a picamera control"""
32-
PropertyDescriptor.__init__(
33-
self, model, observable=False, description=description
34-
)
32+
ThingProperty.__init__(self, model, observable=False, description=description)
3533
self.control_name = control_name
3634
self._getter
3735

@@ -84,20 +82,20 @@ def __init__(self, device_index: int = 0):
8482
self.device_index = device_index
8583
self.camera_configs: dict[str, dict] = {}
8684

87-
stream_resolution = PropertyDescriptor(
85+
stream_resolution = ThingProperty(
8886
tuple[int, int],
8987
initial_value=(1640, 1232),
9088
description="Resolution to use for the MJPEG stream",
9189
)
92-
image_resolution = PropertyDescriptor(
90+
image_resolution = ThingProperty(
9391
tuple[int, int],
9492
initial_value=(3280, 2464),
9593
description="Resolution to use for still images (by default)",
9694
)
97-
mjpeg_bitrate = PropertyDescriptor(
95+
mjpeg_bitrate = ThingProperty(
9896
int, initial_value=0, description="Bitrate for MJPEG stream (best left at 0)"
9997
)
100-
stream_active = PropertyDescriptor(
98+
stream_active = ThingProperty(
10199
bool,
102100
initial_value=False,
103101
description="Whether the MJPEG stream is active",
@@ -116,7 +114,7 @@ def __init__(self, device_index: int = 0):
116114
exposure_time = PicameraControl(
117115
"ExposureTime", int, description="The exposure time in microseconds"
118116
)
119-
sensor_modes = PropertyDescriptor(list[SensorMode], readonly=True)
117+
sensor_modes = ThingProperty(list[SensorMode], readonly=True)
120118

121119
def __enter__(self):
122120
self._picamera = picamera2.Picamera2(camera_num=self.device_index)
@@ -219,7 +217,7 @@ def exposure(self) -> float:
219217
def exposure(self, value):
220218
raise NotImplementedError()
221219

222-
last_frame_index = PropertyDescriptor(int, initial_value=-1)
220+
last_frame_index = ThingProperty(int, initial_value=-1)
223221

224222
mjpeg_stream = MJPEGStreamDescriptor(ringbuffer_size=10)
225223

src/labthings_fastapi/descriptors/property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class ThingSetting(ThingProperty):
232232
233233
The setting otherwise acts just like a normal variable.
234234
"""
235+
235236
@property
236237
def persistent(self):
237238
return True

tests/test_action_cancel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from temp_client import poll_task, task_href
99
from labthings_fastapi.thing import Thing
1010
from labthings_fastapi.decorators import thing_action
11-
from labthings_fastapi.descriptors import PropertyDescriptor
11+
from labthings_fastapi.descriptors import ThingProperty
1212
from labthings_fastapi.dependencies.invocation import CancelHook
1313

1414

1515
class ThingOne(Thing):
16-
counter = PropertyDescriptor(int, 0, observable=False)
16+
counter = ThingProperty(int, 0, observable=False)
1717

1818
@thing_action
1919
def count_slowly(self, cancel: CancelHook, n: int = 10):

tests/test_action_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
from labthings_fastapi.thing import Thing
88
from labthings_fastapi.decorators import thing_action
9-
from labthings_fastapi.descriptors import PropertyDescriptor
9+
from labthings_fastapi.descriptors import ThingProperty
1010

1111

1212
class TestThing(Thing):
@@ -15,7 +15,7 @@ def increment_counter(self):
1515
"""Increment the counter"""
1616
self.counter += 1
1717

18-
counter = PropertyDescriptor(
18+
counter = ThingProperty(
1919
model=int, initial_value=0, readonly=True, description="A pointless counter"
2020
)
2121

tests/test_properties.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from labthings_fastapi.descriptors import PropertyDescriptor
1+
from labthings_fastapi.descriptors import ThingProperty
22
from labthings_fastapi.decorators import thing_property, thing_action
33
from labthings_fastapi.thing import Thing
44
from fastapi.testclient import TestClient
@@ -9,8 +9,8 @@
99

1010

1111
class TestThing(Thing):
12-
boolprop = PropertyDescriptor(bool, False, description="A boolean property")
13-
stringprop = PropertyDescriptor(str, "foo", description="A string property")
12+
boolprop = ThingProperty(bool, False, description="A boolean property")
13+
stringprop = ThingProperty(str, "foo", description="A string property")
1414

1515
_undoc = None
1616

@@ -44,7 +44,7 @@ def toggle_boolprop_from_thread(self):
4444

4545

4646
def test_instantiation_with_type():
47-
prop = PropertyDescriptor(bool, False)
47+
prop = ThingProperty(bool, False)
4848
assert issubclass(prop.model, BaseModel)
4949

5050

@@ -53,7 +53,7 @@ class MyModel(BaseModel):
5353
a: int = 1
5454
b: float = 2.0
5555

56-
prop = PropertyDescriptor(MyModel, MyModel())
56+
prop = ThingProperty(MyModel, MyModel())
5757
assert prop.model is MyModel
5858

5959

@@ -65,7 +65,7 @@ def test_property_get_and_set():
6565
assert after_value.json() == test_str
6666

6767

68-
def test_propertydescriptor():
68+
def test_ThingProperty():
6969
with TestClient(server.app) as client:
7070
r = client.get("/thing/boolprop")
7171
assert r.json() is False

tests/test_thing_lifecycle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from labthings_fastapi.descriptors import PropertyDescriptor
1+
from labthings_fastapi.descriptors import ThingProperty
22
from labthings_fastapi.thing import Thing
33
from fastapi.testclient import TestClient
44
from labthings_fastapi.server import ThingServer
55

66

77
class TestThing(Thing):
8-
alive = PropertyDescriptor(bool, False, description="Is the thing alive?")
8+
alive = ThingProperty(bool, False, description="Is the thing alive?")
99

1010
def __enter__(self):
1111
print("setting up TestThing from __enter__")

0 commit comments

Comments
 (0)