472b26d490819a39475e0a83459e71b0be3f6551
[saartuer.git] / concept_spaceapi.py
1
2
3 class SpaceApi:
4         __init__ (self, waker):
5                 self._state_to_set = None # public write
6                 self._state_last_set = None # public read FIXME why? getter?
7                 self._running = True
8                 self.set_state = ThreadFunction(self._set_state, "Space API")
9                 waker.register(self.set_state, 10.0) # re-try setting the state every 10 seconds
10         
11         def stop (self):
12                 self.set_state.stop()
13         
14         def _set_state (self, state = None):
15                 '''Sets the state, if None: leave state unchanged and re-try if previous attempts failed'''
16                 if state is not None:
17                         self._state_to_set = state
18                 # check if there's something we need to do
19                 if self._state_last_set == self._state_to_set: return
20                 # take action!
21                 error = do_request(stts) # TODO
22                 #TODO logging
23                 if not error:
24                         self.state_last_set = stts