1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Home Assistant stop is more robust

This commit is contained in:
Paulus Schoutsen 2014-11-28 20:22:08 -08:00
parent 89102b5652
commit 006310c883
9 changed files with 16 additions and 16 deletions

View File

@ -610,7 +610,7 @@ class Timer(threading.Thread):
threading.Thread.__init__(self)
self.daemon = True
self._bus = hass.bus
self.hass = hass
self.interval = interval or TIMER_INTERVAL
self._stop = threading.Event()
@ -622,12 +622,12 @@ class Timer(threading.Thread):
hass.listen_once_event(EVENT_HOMEASSISTANT_START,
lambda event: self.start())
hass.listen_once_event(EVENT_HOMEASSISTANT_STOP,
lambda event: self._stop.set())
def run(self):
""" Start the timer. """
self.hass.listen_once_event(EVENT_HOMEASSISTANT_STOP,
lambda event: self._stop.set())
_LOGGER.info("Timer:starting")
last_fired_on_second = -1
@ -658,7 +658,7 @@ class Timer(threading.Thread):
last_fired_on_second = now.second
self._bus.fire(EVENT_TIME_CHANGED, {ATTR_NOW: now})
self.hass.bus.fire(EVENT_TIME_CHANGED, {ATTR_NOW: now})
class HomeAssistantError(Exception):

View File

@ -136,10 +136,6 @@ def setup(hass, config):
lambda event:
threading.Thread(target=server.start, daemon=True).start())
hass.listen_once_event(
ha.EVENT_HOMEASSISTANT_STOP,
lambda event: server.shutdown())
# If no local api set, set one with known information
if isinstance(hass, rem.HomeAssistant) and hass.local_api is None:
hass.local_api = \
@ -173,6 +169,10 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
def start(self):
""" Starts the server. """
self.hass.listen_once_event(
ha.EVENT_HOMEASSISTANT_STOP,
lambda event: self.shutdown())
_LOGGER.info(
"Starting web interface at http://%s:%d", *self.server_address)

View File

@ -33,7 +33,7 @@ class TestChromecast(unittest.TestCase):
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass._pool.stop()
self.hass.stop()
def test_is_on(self):
""" Test is_on method. """

View File

@ -26,7 +26,7 @@ class TestComponentsCore(unittest.TestCase):
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass._pool.stop()
self.hass.stop()
def test_is_on(self):
""" Test is_on method. """

View File

@ -29,7 +29,7 @@ class TestLight(unittest.TestCase):
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass._pool.stop()
self.hass.stop()
user_light_file = self.hass.get_config_path(light.LIGHT_PROFILES_FILE)

View File

@ -22,7 +22,7 @@ class TestSun(unittest.TestCase):
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass._pool.stop()
self.hass.stop()
def test_is_on(self):
""" Test is_on method. """

View File

@ -34,7 +34,7 @@ class TestSwitch(unittest.TestCase):
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass._pool.stop()
self.hass.stop()
def test_methods(self):
""" Test is_on, turn_on, turn_off methods. """

View File

@ -30,7 +30,7 @@ class TestHomeAssistant(unittest.TestCase):
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass._pool.stop()
self.hass.stop()
def test_get_config_path(self):
""" Test get_config_path method. """

View File

@ -24,7 +24,7 @@ class TestLoader(unittest.TestCase):
def tearDown(self): # pylint: disable=invalid-name
""" Stop down stuff we started. """
self.hass._pool.stop()
self.hass.stop()
def test_set_component(self):
""" Test if set_component works. """