diff --git a/SiliconTorch/Device.py b/SiliconTorch/Device.py index 48c1579dc26aeee8c11dcee58c28ba5811aaf536..de441e3be2f7a356775c5ff025c7504cd871a8c7 100644 --- a/SiliconTorch/Device.py +++ b/SiliconTorch/Device.py @@ -55,6 +55,7 @@ class MQTTProperty: +from inspect import signature class MQTTTrigger: @@ -77,6 +78,7 @@ class MQTTTrigger: # ### TODO: !!! ### # ################### def __call__(self, func) -> Callable[[Any], Any]: + print(f'__call__ with {signature(func)}') self.__function = func return self diff --git a/SiliconTorch/PropTest.py b/SiliconTorch/PropTest.py index d1a0d0733f359f3afced17ee47fd15242249c6b2..afcf79c86d070b84cd3a6f8afcc94df48c787266 100644 --- a/SiliconTorch/PropTest.py +++ b/SiliconTorch/PropTest.py @@ -1,65 +1,52 @@ +from inspect import signature -class MyProp: - def __init__(self, getter): - self.__getter = getter +class MQTTTrigger: - def __get__(self, obj, cls): - print('GET IT!!!') - return self.__getter(obj) + def __init__(self, message: str = None, binaryMessage: bytes = None): + self.__function = None -class MyDec: - def __init__(self, *args): - print(f'MyDec[ {args} ]') + if binaryMessage is not None: + self.__message = binaryMessage + elif message is not None: + self.__message = bytes(message, 'UTF-8') + else: + self.__message = b'' - def __call__(*args): - print(f'MyDec.call[ {args} ]') + # ################### + # ### TODO: !!! ### + # ################### + def __call__(self, func=None): + print(f'__CALL__: self is of type {type(self)} and evaluates to str[ {self} ]') + if func is not None: -class MyDesc: + print(f'storing function[ {signature(func)} ]') + self.__function = func - def __get__(self, obj, cls): - return None + return self.__execute + else: + print(f'__call__: executing business logic :)') + print(f'__call__: self is of type {type(self)} and evaluates to str[ {self} ]') + if self.__function is not None: + return self.__function(self) # TODO: is this the right self we supply?! - def __set__(self, obj, value): - pass + def __execute(self): + print(f'__execute: executing business logic :)') + print(f'__execute: self is of type {type(self)} and evaluates to str[ {self} ]') + if self.__function is not None: + return self.__function(self) # TODO: is this the right self we supply?! - def __delete__(self, obj): - pass +class TestDevice: -class C: - xy = MyDesc() - - @MyProp - def wq(self): - print('wq') - return 'foo' - - y = 3 - def x(self): - print(f'y: {__class__.y}') - - - -c = C() - - -class Decorated: - @MyDec - def x(self): print('x') - - @MyDec(1, 2, 3) - def y(self): print('y') - -d = Decorated() - - -#d.x() -#d.y() + @MQTTTrigger(message='restart') + def restart(self): print(f'self[ {self} ] RESTART!!!') + OTA = MQTTTrigger(message='otää otää') +dev = TestDevice()