Files
ha_pstryk/custom_components/pstryk/__init__.py
2025-04-28 11:18:58 +02:00

26 lines
1.0 KiB
Python

import logging
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
"""Only set up hass.data structure (no YAML config)."""
hass.data.setdefault(DOMAIN, {})
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Store API key and forward to sensor platform."""
hass.data[DOMAIN].setdefault(entry.entry_id, {})["api_key"] = entry.data.get("api_key")
await hass.config_entries.async_forward_entry_setup(entry, "sensor")
_LOGGER.debug("Pstryk entry setup: %s", entry.entry_id)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload sensor platform and clear data."""
unload_ok = await hass.config_entries.async_forward_entry_unload(entry, "sensor")
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok