Home Assistant stop is more robust
This commit is contained in:
parent
89102b5652
commit
006310c883
9 changed files with 16 additions and 16 deletions
|
@ -610,7 +610,7 @@ class Timer(threading.Thread):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self._bus = hass.bus
|
self.hass = hass
|
||||||
self.interval = interval or TIMER_INTERVAL
|
self.interval = interval or TIMER_INTERVAL
|
||||||
self._stop = threading.Event()
|
self._stop = threading.Event()
|
||||||
|
|
||||||
|
@ -622,12 +622,12 @@ class Timer(threading.Thread):
|
||||||
hass.listen_once_event(EVENT_HOMEASSISTANT_START,
|
hass.listen_once_event(EVENT_HOMEASSISTANT_START,
|
||||||
lambda event: self.start())
|
lambda event: self.start())
|
||||||
|
|
||||||
hass.listen_once_event(EVENT_HOMEASSISTANT_STOP,
|
|
||||||
lambda event: self._stop.set())
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" Start the timer. """
|
""" Start the timer. """
|
||||||
|
|
||||||
|
self.hass.listen_once_event(EVENT_HOMEASSISTANT_STOP,
|
||||||
|
lambda event: self._stop.set())
|
||||||
|
|
||||||
_LOGGER.info("Timer:starting")
|
_LOGGER.info("Timer:starting")
|
||||||
|
|
||||||
last_fired_on_second = -1
|
last_fired_on_second = -1
|
||||||
|
@ -658,7 +658,7 @@ class Timer(threading.Thread):
|
||||||
|
|
||||||
last_fired_on_second = now.second
|
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):
|
class HomeAssistantError(Exception):
|
||||||
|
|
|
@ -136,10 +136,6 @@ def setup(hass, config):
|
||||||
lambda event:
|
lambda event:
|
||||||
threading.Thread(target=server.start, daemon=True).start())
|
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 no local api set, set one with known information
|
||||||
if isinstance(hass, rem.HomeAssistant) and hass.local_api is None:
|
if isinstance(hass, rem.HomeAssistant) and hass.local_api is None:
|
||||||
hass.local_api = \
|
hass.local_api = \
|
||||||
|
@ -173,6 +169,10 @@ class HomeAssistantHTTPServer(ThreadingMixIn, HTTPServer):
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
""" Starts the server. """
|
""" Starts the server. """
|
||||||
|
self.hass.listen_once_event(
|
||||||
|
ha.EVENT_HOMEASSISTANT_STOP,
|
||||||
|
lambda event: self.shutdown())
|
||||||
|
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Starting web interface at http://%s:%d", *self.server_address)
|
"Starting web interface at http://%s:%d", *self.server_address)
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class TestChromecast(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass._pool.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
""" Test is_on method. """
|
""" Test is_on method. """
|
||||||
|
|
|
@ -26,7 +26,7 @@ class TestComponentsCore(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass._pool.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
""" Test is_on method. """
|
""" Test is_on method. """
|
||||||
|
|
|
@ -29,7 +29,7 @@ class TestLight(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass._pool.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
user_light_file = self.hass.get_config_path(light.LIGHT_PROFILES_FILE)
|
user_light_file = self.hass.get_config_path(light.LIGHT_PROFILES_FILE)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TestSun(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass._pool.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_is_on(self):
|
def test_is_on(self):
|
||||||
""" Test is_on method. """
|
""" Test is_on method. """
|
||||||
|
|
|
@ -34,7 +34,7 @@ class TestSwitch(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass._pool.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_methods(self):
|
def test_methods(self):
|
||||||
""" Test is_on, turn_on, turn_off methods. """
|
""" Test is_on, turn_on, turn_off methods. """
|
||||||
|
|
|
@ -30,7 +30,7 @@ class TestHomeAssistant(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass._pool.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_get_config_path(self):
|
def test_get_config_path(self):
|
||||||
""" Test get_config_path method. """
|
""" Test get_config_path method. """
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TestLoader(unittest.TestCase):
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
""" Stop down stuff we started. """
|
||||||
self.hass._pool.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_set_component(self):
|
def test_set_component(self):
|
||||||
""" Test if set_component works. """
|
""" Test if set_component works. """
|
||||||
|
|
Loading…
Add table
Reference in a new issue