1 """The Govee Light local integration."""
3 from __future__
import annotations
6 from contextlib
import suppress
7 from errno
import EADDRINUSE
10 from govee_local_api.controller
import LISTENING_PORT
16 from .const
import DISCOVERY_TIMEOUT
17 from .coordinator
import GoveeLocalApiCoordinator, GoveeLocalConfigEntry
19 PLATFORMS: list[Platform] = [Platform.LIGHT]
21 _LOGGER = logging.getLogger(__name__)
25 """Set up Govee light local from a config entry."""
28 async
def await_cleanup():
29 cleanup_complete: asyncio.Event = coordinator.cleanup()
30 with suppress(TimeoutError):
31 await asyncio.wait_for(cleanup_complete.wait(), 1)
33 entry.async_on_unload(await_cleanup)
36 await coordinator.start()
38 if ex.errno != EADDRINUSE:
39 _LOGGER.error(
"Start failed, errno: %d", ex.errno)
41 _LOGGER.error(
"Port %s already in use", LISTENING_PORT)
42 raise ConfigEntryNotReady
from ex
44 await coordinator.async_config_entry_first_refresh()
47 async
with asyncio.timeout(delay=DISCOVERY_TIMEOUT):
48 while not coordinator.devices:
49 await asyncio.sleep(delay=1)
50 except TimeoutError
as ex:
51 raise ConfigEntryNotReady
from ex
53 entry.runtime_data = coordinator
54 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
59 """Unload a config entry."""
60 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, GoveeLocalConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, GoveeLocalConfigEntry entry)