Skip to content

Commit

Permalink
Close HTTP client correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl committed Jul 21, 2020
1 parent 24b7190 commit d896200
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions custom_components/tahoma/__init__.py
Expand Up @@ -7,7 +7,7 @@
from tahoma_api.exceptions import BadCredentialsException, TooManyRequestsException

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant

from .const import DOMAIN, TAHOMA_TYPES
Expand Down Expand Up @@ -88,6 +88,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.config_entries.async_forward_entry_setup(entry, platform)
)

async def async_close_client(self, *_):
"""Close HTTP client."""
await client.close()

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_close_client)

return True


Expand All @@ -108,11 +114,3 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
await client.close()

return unload_ok


async def async_shutdown(self, _):
"""Remove all future updates, cancel tasks and close the client."""
self._shutdown = True

for entry in self.hass.data[DOMAIN]:
await entry.get("controller").close()

0 comments on commit d896200

Please sign in to comment.