some tweaks for actor power settings

This commit is contained in:
avollkopf 2021-11-11 11:22:13 +01:00
parent e1c1432f14
commit 80a81c50a2
5 changed files with 12 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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())

View file

@ -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

View file

@ -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