Skip to content
Snippets Groups Projects
Commit 2df6936e authored by fxk8y's avatar fxk8y :spider:
Browse files

………

parent 4bf5f61d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment