Migrate firmata to use async_unload_platforms (#118098)

This commit is contained in:
J. Nick Koston 2024-05-24 23:48:06 -10:00 committed by GitHub
parent 4da125e27b
commit 204cd376cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,5 @@
"""Support for Arduino-compatible Microcontrollers through Firmata."""
import asyncio
from copy import copy
import logging
@ -212,16 +211,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
"""Shutdown and close a Firmata board for a config entry."""
_LOGGER.debug("Closing Firmata board %s", config_entry.data[CONF_NAME])
unload_entries = []
for conf, platform in CONF_PLATFORM_MAP.items():
if conf in config_entry.data:
unload_entries.append(
hass.config_entries.async_forward_entry_unload(config_entry, platform)
)
results = []
if unload_entries:
results = await asyncio.gather(*unload_entries)
results: list[bool] = []
if platforms := [
platform
for conf, platform in CONF_PLATFORM_MAP.items()
if conf in config_entry.data
]:
results.append(
await hass.config_entries.async_unload_platforms(config_entry, platforms)
)
results.append(await hass.data[DOMAIN].pop(config_entry.entry_id).async_reset())
return False not in results