Actor Power fixes

This commit is contained in:
avollkopf 2021-11-15 20:18:33 +01:00
parent 80a81c50a2
commit 2fca6dcdc9
3 changed files with 18 additions and 11 deletions

View file

@ -1 +1 @@
__version__ = "4.0.0.44"
__version__ = "4.0.0.45"

View file

@ -8,7 +8,7 @@ class ActorController(BasicController):
super(ActorController, self).__init__(cbpi, Actor,"actor.json")
self.update_key = "actorupdate"
async def on(self, id, power=100):
async def on(self, id, power=None):
try:
item = self.find_by_id(id)
if item.instance.state is False:
@ -43,10 +43,15 @@ 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 item.instance.set_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()
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict())
except Exception as e:
logging.error("Failed to set power {} {}".format(id, e))
logging.error("Failed to update Actor {} {}".format(id, e))

View file

@ -24,7 +24,9 @@ mode = GPIO.getmode()
if (mode == None):
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):
# Custom property which can be configured by the user
@ -46,10 +48,10 @@ class GPIOActor(CBPiActor):
return 0 if self.inverted == False else 1
async def on_start(self):
self.sampleTime = 5
self.power = 100
self.gpio = self.props.GPIO
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.output(self.gpio, self.get_GPIO_state(0))
self.state = False
@ -89,7 +91,7 @@ class GPIOActor(CBPiActor):
async def set_power(self, power):
self.power = power
await self.cbpi.actor.set_power(self.id,power)
await self.cbpi.actor.actor_update(self.id,power)
pass
@ -128,7 +130,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)
await self.cbpi.actor.actor_update(self.id,self.power)
except:
pass
@ -140,7 +142,7 @@ class GPIOPWMActor(CBPiActor):
async def set_power(self, power):
if self.p and self.state == True:
self.p.ChangeDutyCycle(power)
await self.cbpi.actor.set_power(self.id,power)
await self.cbpi.actor.actor_update(self.id,power)
pass
def get_state(self):