mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-09 17:07:43 +01:00
Actor Power fixes
This commit is contained in:
parent
80a81c50a2
commit
2fca6dcdc9
3 changed files with 18 additions and 11 deletions
|
@ -1 +1 @@
|
||||||
__version__ = "4.0.0.44"
|
__version__ = "4.0.0.45"
|
||||||
|
|
|
@ -8,7 +8,7 @@ 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, power=100):
|
async def on(self, id, power=None):
|
||||||
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:
|
||||||
|
@ -43,10 +43,15 @@ 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
|
await item.instance.set_power(power)
|
||||||
item.power = power
|
except Exception as e:
|
||||||
|
logging.error("Failed to set power {} {}".format(id, e))
|
||||||
|
|
||||||
|
async def actor_update(self, id, power):
|
||||||
|
try:
|
||||||
|
item = self.find_by_id(id)
|
||||||
|
item.power = round(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())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Failed to set power {} {}".format(id, e))
|
logging.error("Failed to update Actor {} {}".format(id, e))
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,9 @@ mode = GPIO.getmode()
|
||||||
if (mode == None):
|
if (mode == None):
|
||||||
GPIO.setmode(GPIO.BCM)
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
|
||||||
@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.Select(label="Inverted", options=["Yes", "No"],description="No: Active on high; Yes: Active on low")])
|
@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.Select(label="Inverted", options=["Yes", "No"],description="No: Active on high; Yes: Active on low"),
|
||||||
|
Property.Select(label="SamplingTime", options=[2,5],description="Time in seconds for power base interval (Default:5)")])
|
||||||
class GPIOActor(CBPiActor):
|
class GPIOActor(CBPiActor):
|
||||||
|
|
||||||
# Custom property which can be configured by the user
|
# Custom property which can be configured by the user
|
||||||
|
@ -46,10 +48,10 @@ class GPIOActor(CBPiActor):
|
||||||
return 0 if self.inverted == False else 1
|
return 0 if self.inverted == False else 1
|
||||||
|
|
||||||
async def on_start(self):
|
async def on_start(self):
|
||||||
self.sampleTime = 5
|
|
||||||
self.power = 100
|
self.power = 100
|
||||||
self.gpio = self.props.GPIO
|
self.gpio = self.props.GPIO
|
||||||
self.inverted = True if self.props.get("Inverted", "No") == "Yes" else False
|
self.inverted = True if self.props.get("Inverted", "No") == "Yes" else False
|
||||||
|
self.sampleTime = int(self.props.get("SamplingTime", 5))
|
||||||
GPIO.setup(self.gpio, GPIO.OUT)
|
GPIO.setup(self.gpio, GPIO.OUT)
|
||||||
GPIO.output(self.gpio, self.get_GPIO_state(0))
|
GPIO.output(self.gpio, self.get_GPIO_state(0))
|
||||||
self.state = False
|
self.state = False
|
||||||
|
@ -89,7 +91,7 @@ class GPIOActor(CBPiActor):
|
||||||
|
|
||||||
async def set_power(self, power):
|
async def set_power(self, power):
|
||||||
self.power = power
|
self.power = power
|
||||||
await self.cbpi.actor.set_power(self.id,power)
|
await self.cbpi.actor.actor_update(self.id,power)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,7 +130,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)
|
await self.cbpi.actor.actor_update(self.id,self.power)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -140,7 +142,7 @@ class GPIOPWMActor(CBPiActor):
|
||||||
async def set_power(self, power):
|
async def set_power(self, power):
|
||||||
if self.p and self.state == True:
|
if self.p and self.state == True:
|
||||||
self.p.ChangeDutyCycle(power)
|
self.p.ChangeDutyCycle(power)
|
||||||
await self.cbpi.actor.set_power(self.id,power)
|
await self.cbpi.actor.actor_update(self.id,power)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
|
|
Loading…
Reference in a new issue