1 """The youless integration."""
3 from datetime
import timedelta
5 from urllib.error
import URLError
7 from youless_api
import YoulessAPI
15 from .const
import DOMAIN
17 PLATFORMS = [Platform.SENSOR]
19 _LOGGER = logging.getLogger(__name__)
23 """Set up youless from a config entry."""
24 api = YoulessAPI(entry.data[CONF_HOST])
27 await hass.async_add_executor_job(api.initialize)
28 except URLError
as exception:
29 raise ConfigEntryNotReady
from exception
31 async
def async_update_data() -> YoulessAPI:
32 """Fetch data from the API."""
33 await hass.async_add_executor_job(api.update)
40 name=
"youless_gateway",
41 update_method=async_update_data,
45 await coordinator.async_config_entry_first_refresh()
47 hass.data.setdefault(DOMAIN, {})
48 hass.data[DOMAIN][entry.entry_id] = coordinator
49 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
55 """Unload a config entry."""
56 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
58 hass.data[DOMAIN].pop(entry.entry_id)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)