From 06bee48fd6ccf0178ce611a68c3f718595086bbc Mon Sep 17 00:00:00 2001 From: Jochen Vothknecht <jochen3120@gmail.com> Date: Fri, 10 Dec 2021 17:03:42 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=A6=E2=80=A6=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SiliconTorch/DecoratorTest.py | 42 +++++++++++++++++++++++++++++++++++ SiliconTorch/Device.py | 24 ++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 SiliconTorch/DecoratorTest.py diff --git a/SiliconTorch/DecoratorTest.py b/SiliconTorch/DecoratorTest.py new file mode 100644 index 0000000..f786f0b --- /dev/null +++ b/SiliconTorch/DecoratorTest.py @@ -0,0 +1,42 @@ + + + +class MyDec: + + def __init__(*args, **kwargs): + print(f'__init__ed with: {args} aaand: {kwargs}') + + def __call__(self, *args, **kwargs): + print(f'called with: {args} aaand: {kwargs}') + + if callable(args[0]): + print('used as decorated with arguments') + return self.execute + else: + print('used as decorator WITHOUT arguments (a long time ago ;) )') + self.execute() + + def execute(*args, **kwargs): + print(f'executed with: {args} aaand: {kwargs}') + + + +class C: + + @MyDec + def decorated0(self, *args): + print(f'decorated0 called with: {args}') + return 'decorated0' + +print('\n' + '-'*120 + '\n') + +class D: + + @MyDec(name='ctor-test') + def decorated42(self, *args): + print(f'decorated42 called with: {args}') + return 'decorated42' + + +c = C() +d = D() diff --git a/SiliconTorch/Device.py b/SiliconTorch/Device.py index a14948a..f687df7 100644 --- a/SiliconTorch/Device.py +++ b/SiliconTorch/Device.py @@ -3,6 +3,9 @@ from typing import Any, Callable +# TODO: dev is stalled! +# at first, we'll design easier things to not loose focus on the project +# Just use simple properties and triggers to get the same (write-only) behavior class MQTTProperty: def __init__(self, name: str = None, initialValue: Any = None, getConvert: Callable[[str], Any] = None, setConvert: Callable[[Any], str] = None, readOnly = False): @@ -49,6 +52,27 @@ class MQTTProperty: + +class MQTTTrigger: + + def __init__(self): + pass + + + + + + + + + + + + + + + + class Device: def __init__(self, torch, name, online = True): -- GitLab