From f659eea65bb61010ef955daaa91dbc227975f988 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 23 Feb 2024 15:33:47 +0100 Subject: [PATCH 1/8] test for aiomqtt 2.0 -> NOT WORKING YET --- cbpi/controller/satellite_controller.py | 14 ++++++-------- setup.py | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cbpi/controller/satellite_controller.py b/cbpi/controller/satellite_controller.py index 7b8e545..d37ea2c 100644 --- a/cbpi/controller/satellite_controller.py +++ b/cbpi/controller/satellite_controller.py @@ -53,7 +53,7 @@ class SatelliteController: except asyncio.CancelledError: pass - self.client = Client(self.host, port=self.port, username=self.username, password=self.password, will=Will(topic="cbpi/disconnect", payload="CBPi Server Disconnected"),client_id=self.client_id) + self.client = Client(self.host, port=self.port, username=self.username, password=self.password, will=Will(topic="cbpi/disconnect", payload="CBPi Server Disconnected"),identifier=self.client_id) self.loop = asyncio.get_event_loop() ## Listen for mqtt messages in an (unawaited) asyncio task task = self.loop.create_task(self.listen()) @@ -67,9 +67,8 @@ class SatelliteController: while True: try: async with self.client as client: - async with client.messages() as messages: await client.subscribe("#") - async for message in messages: + async for message in client.messages: for topic_filter in self.topic_filters: topic = topic_filter[0] method = topic_filter[1] @@ -167,11 +166,10 @@ class SatelliteController: while True: try: if self.client._connected.done(): - async with self.client.messages() as messages: - await self.client.subscribe(topic) - async for message in messages: - if message.topic.matches(topic): - await method(message.payload.decode()) + await self.client.subscribe(topic) + async for message in self.client.messages: + if message.topic.matches(topic): + await method(message.payload.decode()) except asyncio.CancelledError: # Cancel self.logger.warning("Subscription {} Cancelled".format(topic)) diff --git a/setup.py b/setup.py index 8def85b..cda918b 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,7 @@ setup(name='cbpi4', 'click==8.1.7', 'shortuuid==1.0.11', 'tabulate==0.9.0', - 'aiomqtt==1.2.1', + 'aiomqtt==2.0.0', 'inquirer==3.1.3', 'colorama==0.4.6', 'psutil==5.9.6', From beae95f8475bb9901dccf99e37c7250c56ac683f Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:38:50 +0100 Subject: [PATCH 2/8] update dependencies and integrate inverted gpiopwm actor --- cbpi/__init__.py | 2 +- cbpi/extension/gpioactor/__init__.py | 26 +++++++++++++++++++++----- requirements.txt | 4 ++-- setup.py | 4 ++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 70a060f..ae93b5b 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.3.2" +__version__ = "4.3.3.a1" __codename__ = "Winter Storm" diff --git a/cbpi/extension/gpioactor/__init__.py b/cbpi/extension/gpioactor/__init__.py index 93141e9..eb16338 100644 --- a/cbpi/extension/gpioactor/__init__.py +++ b/cbpi/extension/gpioactor/__init__.py @@ -97,7 +97,9 @@ class GPIOActor(CBPiActor): pass -@parameters([Property.Select(label="GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]), Property.Number(label="Frequency", configurable=True)]) +@parameters([Property.Select(label="GPIO", options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]), + Property.Number(label="Frequency", configurable=True), + Property.Select(label="Inverted",options=["Yes","No"],description="Inverts PWM load if set to yes (e.g. 90% = 10%). Default: No")]) class GPIOPWMActor(CBPiActor): # Custom property which can be configured by the user @@ -113,10 +115,14 @@ class GPIOPWMActor(CBPiActor): async def on_start(self): self.gpio = self.props.get("GPIO", None) + self.inverted = self.props.get("Inverted", "No") self.frequency = self.props.get("Frequency", 0.5) if self.gpio is not None: GPIO.setup(self.gpio, GPIO.OUT) - GPIO.output(self.gpio, 0) + if self.inverted == "No": + GPIO.output(self.gpio, 0) + else: + GPIO.output(self.gpio, 1) self.state = False self.power = None self.p = None @@ -135,7 +141,10 @@ class GPIOPWMActor(CBPiActor): try: if self.p is None: self.p = GPIO.PWM(int(self.gpio), float(self.frequency)) - self.p.start(self.power) + if self.inverted == "No": + self.p.start(self.power) + else: + self.p.start(100- self.power) self.state = True # await self.cbpi.actor.actor_update(self.id,self.power) except: @@ -143,12 +152,19 @@ class GPIOPWMActor(CBPiActor): async def off(self): logger.info("PWM ACTOR %s OFF - GPIO %s " % (self.id, self.gpio)) - self.p.ChangeDutyCycle(0) + if self.inverted == "No": + self.p.ChangeDutyCycle(0) + else: + self.p.ChangeDutyCycle(100) + self.state = False async def set_power(self, power): if self.p and self.state == True: - self.p.ChangeDutyCycle(power) + if self.inverted == "No": + self.p.ChangeDutyCycle(power) + else: + self.p.ChangeDutyCycle(100 - power) # Set power to 100-value to invert output await self.cbpi.actor.actor_update(self.id,power) pass diff --git a/requirements.txt b/requirements.txt index 09cd3d4..7c6191b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,8 +8,8 @@ aiohttp-swagger==1.0.16 async-timeout==4.0.3 aiojobs==1.2.1 aiosqlite==0.17.0 -cryptography==41.0.7 -pyopenssl==23.3.0 +cryptography==42.0.4 +pyopenssl==24.0.0 requests==2.31.0 voluptuous==0.13.1 pyfiglet==1.0.2 diff --git a/setup.py b/setup.py index 8def85b..6b7b604 100644 --- a/setup.py +++ b/setup.py @@ -48,8 +48,8 @@ setup(name='cbpi4', "async-timeout==4.0.3", "aiojobs==1.2.1 ", "aiosqlite==0.17.0", - "cryptography==41.0.7", - "pyopenssl==23.3.0", + "cryptography==42.0.4", + "pyopenssl==24.0.0", "requests==2.31.0", "voluptuous==0.13.1", "pyfiglet==1.0.2", From 077365fde6f5e4980adf8631fc6cb58b675b642c Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:35:01 +0100 Subject: [PATCH 3/8] add 2024 to startup log --- cbpi/craftbeerpi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbpi/craftbeerpi.py b/cbpi/craftbeerpi.py index c11295f..dd8a37a 100644 --- a/cbpi/craftbeerpi.py +++ b/cbpi/craftbeerpi.py @@ -263,7 +263,7 @@ class CraftBeerPi: f = Figlet(font='big') logger.warning("\n%s" % f.renderText("CraftBeerPi %s " % self.version)) logger.warning("www.CraftBeerPi.com") - logger.warning("(c) 2021/2022/2023 Manuel Fritsch / Alexander Vollkopf") + logger.warning("(c) 2021 - 2024 Manuel Fritsch / Alexander Vollkopf") def _setup_http_index(self): async def http_index(request): From 1d1a7e8cfbcb1a16ce92ff026cf3923713395215 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 27 Feb 2024 07:20:10 +0100 Subject: [PATCH 4/8] just add topic filters for mqttsensor instead of crating tasks to accommodate new aiomqtt single message queue --- cbpi/__init__.py | 2 +- cbpi/controller/satellite_controller.py | 33 ++++++------------------- cbpi/extension/mqtt_sensor/__init__.py | 17 +++---------- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 5285c9f..87f292b 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.3.2.a10" +__version__ = "4.4.0.a1" __codename__ = "Winter Storm" diff --git a/cbpi/controller/satellite_controller.py b/cbpi/controller/satellite_controller.py index d37ea2c..19f2dc5 100644 --- a/cbpi/controller/satellite_controller.py +++ b/cbpi/controller/satellite_controller.py @@ -157,29 +157,10 @@ class SatelliteController: except Exception as e: self.logger.warning("Failed to send sensorupdate via mqtt: {}".format(e)) - def subcribe(self, topic, method): - task = asyncio.create_task(self._subcribe(topic, method)) - return task - - async def _subcribe(self, topic, method): - self.error=False - while True: - try: - if self.client._connected.done(): - await self.client.subscribe(topic) - async for message in self.client.messages: - if message.topic.matches(topic): - await method(message.payload.decode()) - except asyncio.CancelledError: - # Cancel - self.logger.warning("Subscription {} Cancelled".format(topic)) - self.error=True - except MqttError as e: - self.logger.error("Sub MQTT Exception: {}".format(e)) - except Exception as e: - self.logger.error("Sub Exception: {}".format(e)) - # wait before try to resubscribe - if self.error == True: - break - else: - await asyncio.sleep(5) + def subscribe(self, topic, method): + self.topic_filters.append((topic,method)) + return True + + def unsubscribe(self, topic, method): + self.topic_filters.remove((topic,method)) + return True diff --git a/cbpi/extension/mqtt_sensor/__init__.py b/cbpi/extension/mqtt_sensor/__init__.py index 47114cf..c5b0c0b 100644 --- a/cbpi/extension/mqtt_sensor/__init__.py +++ b/cbpi/extension/mqtt_sensor/__init__.py @@ -24,7 +24,7 @@ class MQTTSensor(CBPiSensor): self.payload_text = self.props.get("PayloadDictionary", None) if self.payload_text != None: self.payload_text = self.payload_text.split('.') - self.mqtt_task = self.cbpi.satellite.subcribe(self.Topic, self.on_message) + self.subscribed = self.cbpi.satellite.subscribe(self.Topic, self.on_message) self.value: float = 999 self.timeout=int(self.props.get("Timeout", 60)) self.starttime = time.time() @@ -55,7 +55,7 @@ class MQTTSensor(CBPiSensor): pass async def on_message(self, message): - val = json.loads(message) + val = json.loads(message.payload.decode()) try: if self.payload_text is not None: for key in self.payload_text: @@ -130,17 +130,8 @@ class MQTTSensor(CBPiSensor): return dict(value=self.value) async def on_stop(self): - was_cancelled=False - if not self.mqtt_task.done(): - logging.info("Task not done -> cancelling") - was_cancelled = self.mqtt_task.cancel() - try: - logging.info("Trying to call cancelled task") - await self.mqtt_task - except asyncio.CancelledError: - logging.info("Task has been Cancelled") - pass - logging.info("Task cancelled: {}".format(was_cancelled)) + self.subscribed = self.cbpi.satellite.unsubscribe(self.Topic, self.on_message) + def setup(cbpi): ''' From 4ce0540f98d20ed0d2ea05da46e155366c43795e Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:38:16 +0100 Subject: [PATCH 5/8] align requirements to setup.py --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7c6191b..6f0f04f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ numpy==1.24.1 cbpi4gui click==8.1.7 importlib_metadata==4.11.1 -aiomqtt==1.2.1 +aiomqtt==2.0.0 psutil==5.9.6 zipp>=0.5 colorama==0.4.6 From ab948d721d0476dddfb8735eef1b3a6c52feabb5 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 22 Mar 2024 07:00:03 +0100 Subject: [PATCH 6/8] update requirements to newer versions --- cbpi/__init__.py | 4 ++-- requirements.txt | 14 +++++++------- setup.py | 14 +++++++------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 87f292b..1651d8b 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.0.a1" -__codename__ = "Winter Storm" +__version__ = "4.4.0.a3" +__codename__ = "Yeast Starter" diff --git a/requirements.txt b/requirements.txt index 6f0f04f..930edab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,22 +8,22 @@ aiohttp-swagger==1.0.16 async-timeout==4.0.3 aiojobs==1.2.1 aiosqlite==0.17.0 -cryptography==42.0.4 +cryptography==42.0.5 pyopenssl==24.0.0 requests==2.31.0 -voluptuous==0.13.1 +voluptuous==0.14.2 pyfiglet==1.0.2 -pandas==1.5.3 +pandas==2.2.1 shortuuid==1.0.11 tabulate==0.9.0 -numpy==1.24.1 +numpy==1.26.4 cbpi4gui click==8.1.7 importlib_metadata==4.11.1 -aiomqtt==2.0.0 -psutil==5.9.6 +aiomqtt==2.0.1 +psutil==5.9.8 zipp>=0.5 colorama==0.4.6 pytest-aiohttp coverage==6.3.1 -inquirer==3.1.3 +inquirer==3.2.4 diff --git a/setup.py b/setup.py index 8cd0905..92ef270 100644 --- a/setup.py +++ b/setup.py @@ -48,22 +48,22 @@ setup(name='cbpi4', "async-timeout==4.0.3", "aiojobs==1.2.1 ", "aiosqlite==0.17.0", - "cryptography==42.0.4", + "cryptography==42.0.5", "pyopenssl==24.0.0", "requests==2.31.0", - "voluptuous==0.13.1", + "voluptuous==0.14.2", "pyfiglet==1.0.2", 'click==8.1.7', 'shortuuid==1.0.11', 'tabulate==0.9.0', - 'aiomqtt==2.0.0', - 'inquirer==3.1.3', + 'aiomqtt==2.0.1', + 'inquirer==3.2.4', 'colorama==0.4.6', - 'psutil==5.9.6', + 'psutil==5.9.8', 'cbpi4gui', 'importlib_metadata', - 'numpy==1.24.1', - 'pandas==1.5.3'] + ( + 'numpy==1.26.4', + 'pandas==2.2.1'] + ( ['rpi-lgpio'] if raspberrypi else [] ), dependency_links=[ From a29aded5d73045cd776a072c3d8eb1df7c943372 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Fri, 12 Apr 2024 17:28:21 +0200 Subject: [PATCH 7/8] update requirements --- cbpi/__init__.py | 2 +- requirements.txt | 8 ++++---- setup.py | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 1651d8b..6799a8d 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.0.a3" +__version__ = "4.4.0.a4" __codename__ = "Yeast Starter" diff --git a/requirements.txt b/requirements.txt index 930edab..96370cf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ typing-extensions>=4 -aiohttp==3.9.3 +aiohttp==3.9.4 aiohttp-auth==0.1.1 aiohttp-route-decorator==0.1.4 aiohttp-security==0.5.0 @@ -9,12 +9,12 @@ async-timeout==4.0.3 aiojobs==1.2.1 aiosqlite==0.17.0 cryptography==42.0.5 -pyopenssl==24.0.0 +pyopenssl==24.1.0 requests==2.31.0 voluptuous==0.14.2 pyfiglet==1.0.2 -pandas==2.2.1 -shortuuid==1.0.11 +pandas==2.2.2 +shortuuid==1.0.13 tabulate==0.9.0 numpy==1.26.4 cbpi4gui diff --git a/setup.py b/setup.py index 92ef270..fab42ac 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ setup(name='cbpi4', long_description_content_type='text/markdown', install_requires=[ "typing-extensions>=4", - "aiohttp==3.9.3", + "aiohttp==3.9.4", "aiohttp-auth==0.1.1", "aiohttp-route-decorator==0.1.4", "aiohttp-security==0.5.0", @@ -49,12 +49,12 @@ setup(name='cbpi4', "aiojobs==1.2.1 ", "aiosqlite==0.17.0", "cryptography==42.0.5", - "pyopenssl==24.0.0", + "pyopenssl==24.1.0", "requests==2.31.0", "voluptuous==0.14.2", "pyfiglet==1.0.2", 'click==8.1.7', - 'shortuuid==1.0.11', + 'shortuuid==1.0.13', 'tabulate==0.9.0', 'aiomqtt==2.0.1', 'inquirer==3.2.4', @@ -63,7 +63,7 @@ setup(name='cbpi4', 'cbpi4gui', 'importlib_metadata', 'numpy==1.26.4', - 'pandas==2.2.1'] + ( + 'pandas==2.2.2'] + ( ['rpi-lgpio'] if raspberrypi else [] ), dependency_links=[ From 33481caa7bb42b3f7db999d7e0fe87635b38069c Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 13 Apr 2024 09:12:59 +0200 Subject: [PATCH 8/8] change rev number from test to release --- cbpi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 6799a8d..92c0b96 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.4.0.a4" +__version__ = "4.4.0" __codename__ = "Yeast Starter"