Update __init__.py
This commit is contained in:
@ -1,13 +1,25 @@
|
||||
import logging
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from .const import DOMAIN
|
||||
|
||||
async def async_setup(hass, config):
|
||||
_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, entry):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
||||
)
|
||||
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, entry):
|
||||
return await hass.config_entries.async_forward_entry_unload(entry, "sensor")
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user