Starting and stopping of modules now via start and shutdown events
parent
6fbadc24e4
commit
371b4c7708
|
@ -2,8 +2,10 @@ import logging
|
||||||
from ConfigParser import SafeConfigParser
|
from ConfigParser import SafeConfigParser
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from homeassistant.common import EVENT_START, EVENT_SHUTDOWN
|
||||||
|
|
||||||
from homeassistant.StateMachine import StateMachine
|
from homeassistant.StateMachine import StateMachine
|
||||||
from homeassistant.EventBus import EventBus
|
from homeassistant.EventBus import EventBus, Event
|
||||||
from homeassistant.HttpInterface import HttpInterface
|
from homeassistant.HttpInterface import HttpInterface
|
||||||
|
|
||||||
from homeassistant.observer.DeviceTracker import DeviceTracker
|
from homeassistant.observer.DeviceTracker import DeviceTracker
|
||||||
|
@ -100,10 +102,9 @@ class HomeAssistant(object):
|
||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.setup_timer().start()
|
self.setup_timer()
|
||||||
|
|
||||||
if self.httpinterface is not None:
|
self.get_event_bus().fire(Event(EVENT_START))
|
||||||
self.httpinterface.start()
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -111,10 +112,6 @@ class HomeAssistant(object):
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print ""
|
print ""
|
||||||
print "Interrupt received. Wrapping up and quiting.."
|
self.eventbus.fire(Event(EVENT_SHUTDOWN))
|
||||||
self.timer.stop()
|
|
||||||
|
|
||||||
if self.httpinterface is not None:
|
|
||||||
self.httpinterface.stop()
|
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
import threading
|
import threading
|
||||||
import urlparse
|
import urlparse
|
||||||
import logging
|
import logging
|
||||||
|
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
from homeassistant.common import EVENT_START, EVENT_SHUTDOWN
|
||||||
|
|
||||||
SERVER_HOST = '127.0.0.1'
|
SERVER_HOST = '127.0.0.1'
|
||||||
SERVER_PORT = 8080
|
SERVER_PORT = 8080
|
||||||
|
@ -22,6 +23,8 @@ class HttpInterface(threading.Thread):
|
||||||
|
|
||||||
self._stop = threading.Event()
|
self._stop = threading.Event()
|
||||||
|
|
||||||
|
eventbus.listen(EVENT_START, lambda event: self.start())
|
||||||
|
eventbus.listen(EVENT_SHUTDOWN, lambda event: self.stop())
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" Start the HTTP interface. """
|
""" Start the HTTP interface. """
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
EVENT_START = "start"
|
||||||
|
EVENT_SHUTDOWN = "shutdown"
|
||||||
|
|
||||||
def ensure_list(parameter):
|
def ensure_list(parameter):
|
||||||
return parameter if isinstance(parameter, list) else [parameter]
|
return parameter if isinstance(parameter, list) else [parameter]
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from datetime import datetime
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from homeassistant.common import EVENT_START, EVENT_SHUTDOWN
|
||||||
from homeassistant.EventBus import Event
|
from homeassistant.EventBus import Event
|
||||||
from homeassistant.util import ensure_list, matcher
|
from homeassistant.util import ensure_list, matcher
|
||||||
|
|
||||||
|
@ -24,11 +25,8 @@ class Timer(threading.Thread):
|
||||||
self.eventbus = eventbus
|
self.eventbus = eventbus
|
||||||
self._stop = threading.Event()
|
self._stop = threading.Event()
|
||||||
|
|
||||||
|
eventbus.listen(EVENT_START, lambda event: self.start())
|
||||||
def stop(self):
|
eventbus.listen(EVENT_SHUTDOWN, lambda event: self._stop.set())
|
||||||
""" Tell the timer to stop. """
|
|
||||||
self._stop.set()
|
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" Start the timer. """
|
""" Start the timer. """
|
||||||
|
|
Loading…
Reference in New Issue