mirror of
https://github.com/sudoxnym/sleepd.git
synced 2026-04-14 11:37:11 +00:00
57 lines
2.1 KiB
Python
57 lines
2.1 KiB
Python
import asyncio
|
|
import logging
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from .const import DOMAIN
|
|
from .services import async_setup_services # Import the service setup function
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
|
|
"""Set up the sleepd - Sleep As Android Status component."""
|
|
_LOGGER.info("Starting setup of the sleepd component")
|
|
return True
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Set up a config entry."""
|
|
_LOGGER.info(f"Starting setup of config entry with ID: {entry.entry_id}")
|
|
|
|
# ensure we have a dict for this integration
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
# merge original data + any saved options so runtime sees edits
|
|
merged = {**entry.data, **entry.options}
|
|
hass.data[DOMAIN][entry.entry_id] = merged
|
|
_LOGGER.debug(
|
|
"Merged entry.data and entry.options for %s: %s",
|
|
entry.entry_id,
|
|
hass.data[DOMAIN][entry.entry_id],
|
|
)
|
|
|
|
# forward setup to sensor and button platforms
|
|
await hass.config_entries.async_forward_entry_setups(entry, ["sensor", "button"])
|
|
|
|
# set up any custom services
|
|
_LOGGER.info("Starting setup of services")
|
|
await async_setup_services(hass)
|
|
_LOGGER.info("Finished setup of services")
|
|
|
|
_LOGGER.info("Finished setup of config entry")
|
|
return True
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
_LOGGER.info(f"Starting unload of config entry with ID: {entry.entry_id}")
|
|
|
|
# unload sensor and button platforms
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, ["sensor", "button"])
|
|
if not unload_ok:
|
|
_LOGGER.error("Failed to unload platforms for sleepd")
|
|
return False
|
|
|
|
# clean up our stored data
|
|
hass.data[DOMAIN].pop(entry.entry_id, None)
|
|
|
|
_LOGGER.info(f"hass.data[{DOMAIN}] after unload: {hass.data.get(DOMAIN)}")
|
|
_LOGGER.info("Finished unload of config entry")
|
|
return True
|