Commit 37cb1be6 authored by Ralf's avatar Ralf
Browse files

update space API concept

parent dfe98478
class SpaceApi: class SpaceApi:
__init__ (self): __init__ (self, waker):
self.state_to_set = None # public write, TODO: getters, setters? self._state_to_set = None # public write
self.state_last_set = None # public read self._state_last_set = None # public read FIXME why? getter?
self._running = True self._running = True
self._t = threading.Thread(target=self.loop) self.set_state = ThreadFunction(self._set_state, "Space API")
_t.start() waker.register(self.set_state, 10.0) # re-try setting the state every 10 seconds
def stop (self): def stop (self):
self._running = False self.set_state.stop()
def loop (self): def _set_state (self, state = None):
while self._running: '''Sets the state, if None: leave state unchanged and re-try if previous attempts failed'''
if (self.state_to_set is not None): if state is not None:
if self.state_to_set != self.state_last_set: self._state_to_set = state
stts = self.state_to_set # cache for parallelism # check if there's something we need to do
error = do_request(stts) # TODO if self._state_last_set == self._state_to_set: return
#TODO logging # take action!
if not error: error = do_request(stts) # TODO
self.state_last_set = stts #TODO logging
#TODO logging if not error:
time.sleep(SPACE_API_LOOP_DELAY) self.state_last_set = stts
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment