Beispiel #1
0
    def async_stop(self, exit_code=0) -> None:
        """Stop Home Assistant and shuts down all threads.

        This method is a coroutine.
        """
        import homeassistant.helpers.aiohttp_client as aiohttp_client

        self.state = CoreState.stopping
        self.async_track_tasks()
        self.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
        yield from self.async_block_till_done()
        self.executor.shutdown()
        self.state = CoreState.not_running

        # cleanup connector pool from aiohttp
        yield from aiohttp_client.async_cleanup_websession(self)

        # cleanup async layer from python logging
        if self.data.get(DATA_ASYNCHANDLER):
            handler = self.data.pop(DATA_ASYNCHANDLER)
            logging.getLogger('').removeHandler(handler)
            yield from handler.async_close(blocking=True)

        self.exit_code = exit_code
        self.loop.stop()
Beispiel #2
0
    def async_stop(self, exit_code=0) -> None:
        """Stop Home Assistant and shuts down all threads.

        This method is a coroutine.
        """
        import homeassistant.helpers.aiohttp_client as aiohttp_client

        self.state = CoreState.stopping
        self.async_track_tasks()
        self.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
        yield from self.async_block_till_done()
        self.executor.shutdown()
        self.state = CoreState.not_running

        # cleanup connector pool from aiohttp
        yield from aiohttp_client.async_cleanup_websession(self)

        # cleanup async layer from python logging
        if self.data.get(DATA_ASYNCHANDLER):
            handler = self.data.pop(DATA_ASYNCHANDLER)
            logging.getLogger('').removeHandler(handler)
            yield from handler.async_close(blocking=True)

        self.exit_code = exit_code
        self.loop.stop()
    def test_get_clientsession_cleanup_without_ssl(self):
        """Test init clientsession with ssl."""
        run_callback_threadsafe(self.hass.loop, client.async_get_clientsession,
                                self.hass, False).result()

        assert isinstance(self.hass.data[client.DATA_CLIENTSESSION_NOTVERIFY],
                          aiohttp.ClientSession)
        assert isinstance(self.hass.data[client.DATA_CONNECTOR_NOTVERIFY],
                          aiohttp.TCPConnector)

        run_coroutine_threadsafe(client.async_cleanup_websession(self.hass),
                                 self.hass.loop).result()

        assert self.hass.data[client.DATA_CLIENTSESSION_NOTVERIFY].closed
        assert self.hass.data[client.DATA_CONNECTOR_NOTVERIFY].closed
    def test_get_clientsession_cleanup(self):
        """Test init clientsession with ssl."""
        run_callback_threadsafe(self.hass.loop, client.async_get_clientsession,
                                self.hass).result()

        assert isinstance(
            self.hass.data[client.DATA_CLIENTSESSION], aiohttp.ClientSession)
        assert isinstance(
            self.hass.data[client.DATA_CONNECTOR], aiohttp.TCPConnector)

        run_coroutine_threadsafe(
            client.async_cleanup_websession(self.hass), self.hass.loop
        ).result()

        assert self.hass.data[client.DATA_CLIENTSESSION].closed
        assert self.hass.data[client.DATA_CONNECTOR].closed