Update on pwm test

-> set power action should now update also directly in dashboard
This commit is contained in:
avollkopf 2021-11-08 14:04:28 +01:00
parent 4c543b46f7
commit 2462f9329a
4 changed files with 19 additions and 4 deletions

View file

@ -88,5 +88,13 @@ class CBPiActor(metaclass=ABCMeta):
'''
pass
async def set_power(self,power):
self.power=power
'''
Code to switch the actor off
:return: None
'''
return dict(power=self.power)
pass

View file

@ -44,7 +44,7 @@ class CBPiBase(metaclass=ABCMeta):
actor = self.cbpi.actor.find_by_id(id)
return actor.get("instance").get_state()
except:
logging.error("Faild to read actor state in step - actor {}".format(id))
logging.error("Failed to read actor state in step - actor {}".format(id))
return None
async def actor_on(self,id):
@ -60,4 +60,8 @@ class CBPiBase(metaclass=ABCMeta):
except Exception as e:
pass
async def actor_set_power(self,id,power):
try:
await self.cbpi.actor.set_power(id,power)
except Exception as e:
pass

View file

@ -42,6 +42,7 @@ class ActorController(BasicController):
try:
item = self.find_by_id(id)
item.power = 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))

View file

@ -85,7 +85,6 @@ class GPIOPWMActor(CBPiActor):
self.power = 100
item = self.cbpi.actor.find_by_id(self.id)
item.power = self.power
self.cbpi.push_update("cbpi/actor/"+self.id, item.to_dict())
await self.set_power(self.power)
async def on_start(self):
@ -100,6 +99,8 @@ class GPIOPWMActor(CBPiActor):
pass
async def on(self, power = None):
if power is not None:
self.power = power
logger.info("PWM ACTOR %s ON - GPIO %s - Frequency %s - Power %s" % (self.id, self.gpio,self.frequency,self.power))
try:
@ -118,6 +119,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)
pass
def get_state(self):