mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 22:48:16 +01:00
added power to actor dataclass
This commit is contained in:
parent
3bc70f8c7f
commit
4c543b46f7
4 changed files with 27 additions and 9 deletions
|
@ -20,6 +20,7 @@ class CBPiActor(metaclass=ABCMeta):
|
|||
self.data_logger = None
|
||||
self.state = False
|
||||
self.running = False
|
||||
self.power = 100
|
||||
|
||||
def init(self):
|
||||
pass
|
||||
|
|
|
@ -55,13 +55,14 @@ class Actor:
|
|||
name: str = None
|
||||
props: Props = Props()
|
||||
state: bool = False
|
||||
power: int = 100
|
||||
type: str = None
|
||||
instance: str = None
|
||||
|
||||
def __str__(self):
|
||||
return "name={} props={}, state={}, type={}".format(self.name, self.props, self.state, self.type)
|
||||
return "name={} props={}, state={}, type={}, power={}".format(self.name, self.props, self.state, self.type, self.power)
|
||||
def to_dict(self):
|
||||
return dict(id=self.id, name=self.name, type=self.type, props=self.props.to_dict(), state2="HELLO WORLD", state=self.instance.get_state())
|
||||
return dict(id=self.id, name=self.name, type=self.type, props=self.props.to_dict(), state2="HELLO WORLD", state=self.instance.get_state(), power=self.power)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
@ -17,7 +17,7 @@ class ActorController(BasicController):
|
|||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict(), True)
|
||||
|
||||
except Exception as e:
|
||||
logging.error("Faild to switch on Actor {} {}".format(id, e))
|
||||
logging.error("Failed to switch on Actor {} {}".format(id, e))
|
||||
|
||||
async def off(self, id):
|
||||
try:
|
||||
|
@ -27,7 +27,7 @@ class ActorController(BasicController):
|
|||
await self.push_udpate()
|
||||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict())
|
||||
except Exception as e:
|
||||
logging.error("Faild to switch on Actor {} {}".format(id, e), True)
|
||||
logging.error("Failed to switch on Actor {} {}".format(id, e), True)
|
||||
|
||||
async def toogle(self, id):
|
||||
try:
|
||||
|
@ -36,5 +36,13 @@ class ActorController(BasicController):
|
|||
await instance.toggle()
|
||||
self.cbpi.push_update("cbpi/actor/update", item.to_dict())
|
||||
except Exception as e:
|
||||
logging.error("Faild to switch on Actor {} {}".format(id, e))
|
||||
|
||||
logging.error("Failed to toggle Actor {} {}".format(id, e))
|
||||
|
||||
async def set_power(self, id, power):
|
||||
try:
|
||||
item = self.find_by_id(id)
|
||||
item.power = power
|
||||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict())
|
||||
except Exception as e:
|
||||
logging.error("Failed to set power {} {}".format(id, e))
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ class GPIOActor(CBPiActor):
|
|||
return 0 if self.inverted == False else 1
|
||||
|
||||
async def on_start(self):
|
||||
self.power = 100
|
||||
self.gpio = self.props.GPIO
|
||||
self.inverted = True if self.props.get("Inverted", "No") == "Yes" else False
|
||||
GPIO.setup(self.gpio, GPIO.OUT)
|
||||
|
@ -81,9 +82,11 @@ class GPIOPWMActor(CBPiActor):
|
|||
if self.power < 0:
|
||||
self.power = 0
|
||||
if self.power > 100:
|
||||
self.power = 100
|
||||
if self.p and self.state == True:
|
||||
self.p.ChangeDutyCycle(self.power)
|
||||
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):
|
||||
self.gpio = self.props.get("GPIO", None)
|
||||
|
@ -112,6 +115,11 @@ class GPIOPWMActor(CBPiActor):
|
|||
self.p.ChangeDutyCycle(0)
|
||||
self.state = False
|
||||
|
||||
async def set_power(self, power):
|
||||
if self.p and self.state == True:
|
||||
self.p.ChangeDutyCycle(power)
|
||||
pass
|
||||
|
||||
def get_state(self):
|
||||
return self.state
|
||||
|
||||
|
|
Loading…
Reference in a new issue