Fix application state and add new optional config attribute: "initial_state"

* Move State handling to misc, to avoid circular imports
* Add optional config attribute "initial_state"
This commit is contained in:
gcarq
2017-09-09 00:31:40 +02:00
parent 996beae770
commit a4b2f4e4b9
6 changed files with 118 additions and 107 deletions

36
misc.py
View File

@@ -1,3 +1,36 @@
import enum
from wrapt import synchronized
class State(enum.Enum):
RUNNING = 0
STOPPED = 1
# Current application state
_STATE = State.STOPPED
@synchronized
def update_state(state: State) -> None:
"""
Updates the application state
:param state: new state
:return: None
"""
global _STATE
_STATE = state
@synchronized
def get_state() -> State:
"""
Gets the current application state
:return:
"""
return _STATE
# Required json-schema for user specified config
CONF_SCHEMA = {
@@ -25,7 +58,8 @@ CONF_SCHEMA = {
'chat_id': {'type': 'string'},
},
'required': ['enabled', 'token', 'chat_id']
}
},
'initial_state': {'type': 'string', 'enum': ['running', 'stopped']},
},
'definitions': {
'exchange': {