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: ...@@ -55,6 +55,7 @@ class MQTTProperty:
from inspect import signature
class MQTTTrigger: class MQTTTrigger:
...@@ -77,6 +78,7 @@ class MQTTTrigger: ...@@ -77,6 +78,7 @@ class MQTTTrigger:
# ### TODO: !!! ### # ### TODO: !!! ###
# ################### # ###################
def __call__(self, func) -> Callable[[Any], Any]: def __call__(self, func) -> Callable[[Any], Any]:
print(f'__call__ with {signature(func)}')
self.__function = func self.__function = func
return self return self
......
from inspect import signature
class MyProp:
def __init__(self, getter): class MQTTTrigger:
self.__getter = getter
def __get__(self, obj, cls): def __init__(self, message: str = None, binaryMessage: bytes = None):
print('GET IT!!!')
return self.__getter(obj)
self.__function = None
class MyDec: if binaryMessage is not None:
def __init__(self, *args): self.__message = binaryMessage
print(f'MyDec[ {args} ]') 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 self.__execute
return None 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): def __execute(self):
pass 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: @MQTTTrigger(message='restart')
xy = MyDesc() def restart(self): print(f'self[ {self} ] RESTART!!!')
@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()
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