craftbeerpi4-pione/core/api/step.py

64 lines
1.4 KiB
Python
Raw Normal View History

2018-12-05 07:31:12 +01:00
import time
import asyncio
import logging
2018-12-03 22:16:03 +01:00
class Step(object):
2018-12-05 07:31:12 +01:00
__dirty = False
managed_fields = []
_interval = 0.1
def __init__(self, *args, **kwargs):
self.logger = logging.getLogger(__name__)
for a in kwargs:
super(Step, self).__setattr__(a, kwargs.get(a))
self.id = kwargs.get("id")
self.stop = False
self.start = time.time()
def running(self):
if self.stop is False:
return False
return True
async def _run(self):
i = 0
while i < 20:
2018-12-05 07:31:12 +01:00
try:
await self.run()
except Exception as e:
pass
#logging.exception("Step Error")
print("INTER",self._interval)
await asyncio.sleep(self._interval)
i = i + 1
if self.is_dirty():
# Now we have to store the managed props
self.reset_dirty()
2018-12-03 22:16:03 +01:00
async def run(self):
2018-12-05 07:31:12 +01:00
print("NOTING IMPLEMENTED")
2018-12-03 22:16:03 +01:00
pass
def stop(self):
2018-12-05 07:31:12 +01:00
pass
def reset(self):
pass
def is_dirty(self):
return self.__dirty
def reset_dirty(self):
self.__dirty = False
def __setattr__(self, name, value):
if name != "_Step__dirty" and name in self.managed_fields:
self.__dirty = True
super(Step, self).__setattr__(name, value)
else:
super(Step, self).__setattr__(name, value)