mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-09 17:07:43 +01:00
some tweaks for actor power settings
This commit is contained in:
parent
e1c1432f14
commit
80a81c50a2
5 changed files with 12 additions and 7 deletions
|
@ -89,11 +89,10 @@ class CBPiActor(metaclass=ABCMeta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def set_power(self,power):
|
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)
|
return dict(power=self.power)
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -47,10 +47,10 @@ class CBPiBase(metaclass=ABCMeta):
|
||||||
logging.error("Failed to read actor state in step - actor {}".format(id))
|
logging.error("Failed to read actor state in step - actor {}".format(id))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
async def actor_on(self,id):
|
async def actor_on(self,id,power=100):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.cbpi.actor.on(id)
|
await self.cbpi.actor.on(id,power)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,15 @@ class ActorController(BasicController):
|
||||||
super(ActorController, self).__init__(cbpi, Actor,"actor.json")
|
super(ActorController, self).__init__(cbpi, Actor,"actor.json")
|
||||||
self.update_key = "actorupdate"
|
self.update_key = "actorupdate"
|
||||||
|
|
||||||
async def on(self, id):
|
async def on(self, id, power=100):
|
||||||
try:
|
try:
|
||||||
item = self.find_by_id(id)
|
item = self.find_by_id(id)
|
||||||
if item.instance.state is False:
|
if item.instance.state is False:
|
||||||
await item.instance.on()
|
await item.instance.on(power)
|
||||||
await self.push_udpate()
|
await self.push_udpate()
|
||||||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict(), True)
|
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict(), True)
|
||||||
|
else:
|
||||||
|
await self.set_power(id, power)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Failed to switch on Actor {} {}".format(id, 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):
|
async def set_power(self, id, power):
|
||||||
try:
|
try:
|
||||||
item = self.find_by_id(id)
|
item = self.find_by_id(id)
|
||||||
|
item.instance.power = power
|
||||||
item.power = power
|
item.power = power
|
||||||
await self.push_udpate()
|
await self.push_udpate()
|
||||||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict())
|
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict())
|
||||||
|
|
|
@ -103,6 +103,7 @@ class SystemController:
|
||||||
f=open(self.path, "w")
|
f=open(self.path, "w")
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
|
self.cbpi.notify("Success", "SVG file ({}) has been uploaded.".format(filename), NotificationType.SUCCESS)
|
||||||
except:
|
except:
|
||||||
self.cbpi.notify("Error", "SVG upload failed", NotificationType.ERROR)
|
self.cbpi.notify("Error", "SVG upload failed", NotificationType.ERROR)
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -57,6 +57,7 @@ class GPIOActor(CBPiActor):
|
||||||
async def on(self, power = None):
|
async def on(self, power = None):
|
||||||
if power is not None:
|
if power is not None:
|
||||||
self.power = power
|
self.power = power
|
||||||
|
await self.set_power(self.power)
|
||||||
|
|
||||||
logger.info("ACTOR %s ON - GPIO %s " % (self.id, self.gpio))
|
logger.info("ACTOR %s ON - GPIO %s " % (self.id, self.gpio))
|
||||||
GPIO.output(self.gpio, self.get_GPIO_state(1))
|
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 = GPIO.PWM(int(self.gpio), float(self.frequency))
|
||||||
self.p.start(self.power)
|
self.p.start(self.power)
|
||||||
self.state = True
|
self.state = True
|
||||||
|
await self.cbpi.actor.set_power(self.id,self.power)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue