mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-12-23 05:54:58 +01:00
BasicController start() and stop() functions manages item.instance.running state
Also changes usage of 'while True' inside run() functions to 'while self.running == True'
This commit is contained in:
parent
7a5e852121
commit
a9546bc40c
6 changed files with 12 additions and 12 deletions
|
@ -76,9 +76,9 @@ class BasicController:
|
||||||
async def stop(self, id):
|
async def stop(self, id):
|
||||||
logging.info("{} Stop Id {} ".format(self.name, id))
|
logging.info("{} Stop Id {} ".format(self.name, id))
|
||||||
try:
|
try:
|
||||||
print("STOP NOW")
|
|
||||||
item = self.find_by_id(id)
|
item = self.find_by_id(id)
|
||||||
await item.instance.stop()
|
await item.instance.stop()
|
||||||
|
item.instance.running = False
|
||||||
await self.push_udpate()
|
await self.push_udpate()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("{} Cant stop {} - {}".format(self.name, id, e))
|
logging.error("{} Cant stop {} - {}".format(self.name, id, e))
|
||||||
|
@ -87,7 +87,7 @@ class BasicController:
|
||||||
logging.info("{} Start Id {} ".format(self.name, id))
|
logging.info("{} Start Id {} ".format(self.name, id))
|
||||||
try:
|
try:
|
||||||
item = self.find_by_id(id)
|
item = self.find_by_id(id)
|
||||||
if item.instance is not None and item.instance.state is True:
|
if item.instance is not None and item.instance.running is True:
|
||||||
logging.warning("{} already running {}".format(self.name, id))
|
logging.warning("{} already running {}".format(self.name, id))
|
||||||
return
|
return
|
||||||
if item.type is None:
|
if item.type is None:
|
||||||
|
@ -97,6 +97,7 @@ class BasicController:
|
||||||
item.instance = clazz(self.cbpi, item.id, item.props)
|
item.instance = clazz(self.cbpi, item.id, item.props)
|
||||||
|
|
||||||
await item.instance.start()
|
await item.instance.start()
|
||||||
|
item.instance.running = True
|
||||||
item.instance.task = self._loop.create_task(item.instance._run())
|
item.instance.task = self._loop.create_task(item.instance._run())
|
||||||
|
|
||||||
logging.info("{} started {}".format(self.name, id))
|
logging.info("{} started {}".format(self.name, id))
|
||||||
|
|
|
@ -15,7 +15,7 @@ class CustomSensor(CBPiSensor):
|
||||||
self.value = 0
|
self.value = 0
|
||||||
async def run(self):
|
async def run(self):
|
||||||
|
|
||||||
while True:
|
while self.running == True:
|
||||||
self.value = random.randint(10,100)
|
self.value = random.randint(10,100)
|
||||||
self.log_data(self.value)
|
self.log_data(self.value)
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ class GPIOActor(CBPiActor):
|
||||||
return self.state
|
return self.state
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
while True:
|
while self.running == True:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class GPIOPWMActor(CBPiActor):
|
||||||
return self.state
|
return self.state
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
while True:
|
while self.runnin == True:
|
||||||
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Hysteresis(CBPiKettleLogic):
|
||||||
# self.get_actor_state()
|
# self.get_actor_state()
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while self.running == True:
|
||||||
|
|
||||||
sensor_value = self.get_sensor_value(self.kettle.sensor).get("value")
|
sensor_value = self.get_sensor_value(self.kettle.sensor).get("value")
|
||||||
target_temp = self.get_kettle_target_temp(self.id)
|
target_temp = self.get_kettle_target_temp(self.id)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class MashStep(CBPiStep):
|
||||||
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
while True:
|
while self.running == True:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
sensor_value = self.get_sensor_value(self.props.Sensor)
|
sensor_value = self.get_sensor_value(self.props.Sensor)
|
||||||
if sensor_value.get("value") >= int(self.props.Temp) and self.timer == None:
|
if sensor_value.get("value") >= int(self.props.Temp) and self.timer == None:
|
||||||
|
@ -82,7 +82,7 @@ class WaitStep(CBPiStep):
|
||||||
self.timer = Timer(int(self.props.Timer) * 60,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
self.timer = Timer(int(self.props.Timer) * 60,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
while True:
|
while self.running == True:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
return StepResult.DONE
|
return StepResult.DONE
|
||||||
|
|
||||||
|
@ -113,8 +113,7 @@ class ActorStep(CBPiStep):
|
||||||
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
self.timer = Timer(int(self.props.Timer) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
|
while self.running == True:
|
||||||
while True:
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
return StepResult.DONE
|
return StepResult.DONE
|
||||||
|
|
||||||
|
@ -154,7 +153,7 @@ class BoilStep(CBPiStep):
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
while True:
|
while self.running == True:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
sensor_value = self.get_sensor_value(self.props.Sensor)
|
sensor_value = self.get_sensor_value(self.props.Sensor)
|
||||||
if sensor_value is not None and sensor_value.get("value") >= int(self.props.Temp) and self.timer == None:
|
if sensor_value is not None and sensor_value.get("value") >= int(self.props.Temp) and self.timer == None:
|
||||||
|
|
|
@ -77,7 +77,7 @@ class OneWire(CBPiSensor):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
while True:
|
while self.running == True:
|
||||||
self.value = self.t.value
|
self.value = self.t.value
|
||||||
|
|
||||||
self.log_data(self.value)
|
self.log_data(self.value)
|
||||||
|
|
Loading…
Reference in a new issue