From 6e621c5f74864822f8d66ce12d054edddc28903d Mon Sep 17 00:00:00 2001 From: Jochen Vothknecht <jochen3120@gmail.com> Date: Thu, 9 Dec 2021 08:54:21 +0100 Subject: [PATCH] Moar prop dev --- SiliconTorch/Device.py | 15 +++++++++++++-- SiliconTorch/PropTest.py | 4 ++++ SiliconTorch/fxCyanF.py | 2 +- scripting/CyanLightSparkling.py | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/SiliconTorch/Device.py b/SiliconTorch/Device.py index 3f33490..a14948a 100644 --- a/SiliconTorch/Device.py +++ b/SiliconTorch/Device.py @@ -10,6 +10,8 @@ class MQTTProperty: self.__ro = readOnly self.__value = initialValue + self.__mqtt = None + if getConvert is not None: self.__name = getConvert.__name__ self.__getConvert = getConvert @@ -21,17 +23,26 @@ class MQTTProperty: else: self.__setConvert = lambda x: x + if name is not None: + self.__name = name def __call__(self, getConvert: Callable[[str], Any]): self.__getConvert = getConvert + if self.__name is not None: + self.__name = getConvert.__name__ + def __get__(self, obj, cls): - pass + if self.__value is not None: + return self.__value + else: + raise AttributeError('not in sync') def __set__(self, obj, value): if self.__ro: raise AttributeError(f'MQTTProperty[ {self.__name} ] is read-only') - pass + + # TODO: publish value! def __del__(*ignored): raise AttributeError('deletion not supported') diff --git a/SiliconTorch/PropTest.py b/SiliconTorch/PropTest.py index b821156..d1a0d07 100644 --- a/SiliconTorch/PropTest.py +++ b/SiliconTorch/PropTest.py @@ -38,6 +38,10 @@ class C: def wq(self): print('wq') return 'foo' + + y = 3 + def x(self): + print(f'y: {__class__.y}') diff --git a/SiliconTorch/fxCyanF.py b/SiliconTorch/fxCyanF.py index 8cd4f1a..7b1f853 100644 --- a/SiliconTorch/fxCyanF.py +++ b/SiliconTorch/fxCyanF.py @@ -59,7 +59,7 @@ class Receiver: self._socket = socket(AF_INET, SOCK_DGRAM) self._socket.bind((host, port)) - self._callbacks = Set() + self._callbacks = set() t = Thread(target=self._recvLoop) t.daemon = True diff --git a/scripting/CyanLightSparkling.py b/scripting/CyanLightSparkling.py index f07c0c5..c771bf4 100755 --- a/scripting/CyanLightSparkling.py +++ b/scripting/CyanLightSparkling.py @@ -7,7 +7,7 @@ import random from socket import * -fps = 3 +fps = 4 pixels = 50 port = 4213 -- GitLab