fjaraskupan: Make sure we stop bleak on home assistant stop (#74545)

* Make sure we stop bleak on home assistant stop

* Fix typing

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
pull/74579/head
Joakim Plate 2022-07-07 08:40:10 +02:00 committed by GitHub
parent c303d6e717
commit 104d236646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -12,8 +12,8 @@ from bleak.backends.scanner import AdvertisementData
from fjaraskupan import Device, State, device_filter
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, Platform
from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.helpers.dispatcher import (
async_dispatcher_connect,
async_dispatcher_send,
@ -131,6 +131,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
scanner.register_detection_callback(detection_callback)
await scanner.start()
async def on_hass_stop(event: Event) -> None:
await scanner.stop()
entry.async_on_unload(
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, on_hass_stop)
)
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
return True