From 80a81c50a2cc5efef7db3e2a41e2495fb657820c Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 11 Nov 2021 11:22:13 +0100 Subject: [PATCH] some tweaks for actor power settings --- cbpi/api/actor.py | 5 ++--- cbpi/api/base.py | 4 ++-- cbpi/controller/actor_controller.py | 7 +++++-- cbpi/controller/system_controller.py | 1 + cbpi/extension/gpioactor/__init__.py | 2 ++ 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cbpi/api/actor.py b/cbpi/api/actor.py index 099ba46..ecf4a26 100644 --- a/cbpi/api/actor.py +++ b/cbpi/api/actor.py @@ -89,11 +89,10 @@ class CBPiActor(metaclass=ABCMeta): pass async def set_power(self,power): - self.power=power ''' - Code to switch the actor off + Code to set power for actor - :return: None + :return: dict power ''' return dict(power=self.power) pass diff --git a/cbpi/api/base.py b/cbpi/api/base.py index ee54ce4..844e645 100644 --- a/cbpi/api/base.py +++ b/cbpi/api/base.py @@ -47,10 +47,10 @@ class CBPiBase(metaclass=ABCMeta): logging.error("Failed to read actor state in step - actor {}".format(id)) return None - async def actor_on(self,id): + async def actor_on(self,id,power=100): try: - await self.cbpi.actor.on(id) + await self.cbpi.actor.on(id,power) except Exception as e: pass diff --git a/cbpi/controller/actor_controller.py b/cbpi/controller/actor_controller.py index a4e7c45..a4ea4b3 100644 --- a/cbpi/controller/actor_controller.py +++ b/cbpi/controller/actor_controller.py @@ -8,13 +8,15 @@ class ActorController(BasicController): super(ActorController, self).__init__(cbpi, Actor,"actor.json") self.update_key = "actorupdate" - async def on(self, id): + async def on(self, id, power=100): try: item = self.find_by_id(id) if item.instance.state is False: - await item.instance.on() + await item.instance.on(power) await self.push_udpate() self.cbpi.push_update("cbpi/actor/"+id, item.to_dict(), True) + else: + await self.set_power(id, power) except Exception as e: logging.error("Failed to switch on Actor {} {}".format(id, e)) @@ -41,6 +43,7 @@ class ActorController(BasicController): async def set_power(self, id, power): try: item = self.find_by_id(id) + item.instance.power = power item.power = power await self.push_udpate() self.cbpi.push_update("cbpi/actor/"+id, item.to_dict()) diff --git a/cbpi/controller/system_controller.py b/cbpi/controller/system_controller.py index cdb9c99..718edfa 100644 --- a/cbpi/controller/system_controller.py +++ b/cbpi/controller/system_controller.py @@ -103,6 +103,7 @@ class SystemController: f=open(self.path, "w") f.write(content) f.close() + self.cbpi.notify("Success", "SVG file ({}) has been uploaded.".format(filename), NotificationType.SUCCESS) except: self.cbpi.notify("Error", "SVG upload failed", NotificationType.ERROR) pass diff --git a/cbpi/extension/gpioactor/__init__.py b/cbpi/extension/gpioactor/__init__.py index b81f388..5d336f5 100644 --- a/cbpi/extension/gpioactor/__init__.py +++ b/cbpi/extension/gpioactor/__init__.py @@ -57,6 +57,7 @@ class GPIOActor(CBPiActor): async def on(self, power = None): if power is not None: self.power = power + await self.set_power(self.power) logger.info("ACTOR %s ON - GPIO %s " % (self.id, self.gpio)) GPIO.output(self.gpio, self.get_GPIO_state(1)) @@ -127,6 +128,7 @@ class GPIOPWMActor(CBPiActor): self.p = GPIO.PWM(int(self.gpio), float(self.frequency)) self.p.start(self.power) self.state = True + await self.cbpi.actor.set_power(self.id,self.power) except: pass