Skip to content

Commit 75b7a2b

Browse files
author
Jeroen van der Heijden
committed
Update with enum support
1 parent 8e1430b commit 75b7a2b

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,20 @@ When adding a new brick, for example using the following code:
656656
color name: RED
657657
color value: #f00
658658
```
659+
660+
If you do not care about having defined the `Color` class, then you can drop this class and change the
661+
color specification to the plain string `"Enum"`. For example:
662+
663+
```python
664+
class Brick(Thing):
665+
color = 'Enum'
666+
667+
def on_init(self, *args, **kwars):
668+
super().on_init(*args, **kwars)
669+
print(f'''
670+
Init Brick:
671+
id: {self.id()}
672+
color name: {self.color.name}
673+
color value: {self.color.value}
674+
''')
675+
```

thingsdb/model/prop.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ def unpack(self, collection):
7272
if spec == 'Thing' and cb_type is None:
7373
spec, kwargs['watch'] = 'thing', True
7474

75-
self.vconv = self.get_conv(
76-
spec, is_nillable, **kwargs
77-
if spec == 'any' or spec == 'thing' else {})
75+
if spec == 'Enum' and cb_type is None:
76+
self.vconv = self.get_conv('enum', collection=collection)
77+
else:
78+
self.vconv = self.get_conv(
79+
spec, is_nillable, **kwargs
80+
if spec == 'any' or spec == 'thing' else {})
7881

7982
if self.vconv is None:
8083
assert callable(cb_type), \

thingsdb/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.5.3'
1+
__version__ = '0.6.0'

0 commit comments

Comments
 (0)