|
1 | 1 | """The Speedport integration.""" |
2 | | - |
3 | 2 | from homeassistant.config_entries import ConfigEntry |
4 | 3 | from homeassistant.const import Platform |
5 | 4 | from homeassistant.core import HomeAssistant |
6 | 5 | from homeassistant.helpers import aiohttp_client |
7 | 6 | from speedport import Speedport |
8 | 7 |
|
| 8 | +from .config_flow import OptionsFlowHandler |
9 | 9 | from .const import DOMAIN |
10 | 10 |
|
11 | 11 | PLATFORMS: list[Platform] = [ |
|
19 | 19 |
|
20 | 20 | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: |
21 | 21 | """Set up Speedport from a config entry.""" |
22 | | - session = aiohttp_client.async_get_clientsession(hass) |
23 | 22 |
|
24 | 23 | hass.data.setdefault(DOMAIN, {}) |
25 | 24 | speedport = await Speedport( |
26 | | - host=entry.data["host"], password=entry.data["password"], session=session |
| 25 | + host=entry.data["host"], |
| 26 | + password=entry.data["password"], |
| 27 | + session=aiohttp_client.async_get_clientsession(hass), |
| 28 | + pause_time=entry.options.get("pause_time", 5), |
27 | 29 | ).create() |
28 | 30 | hass.data[DOMAIN][entry.entry_id] = speedport |
29 | 31 | hass.data[DOMAIN]["coordinators"] = {} |
30 | 32 |
|
| 33 | + entry.async_on_unload(entry.add_update_listener(update_listener)) |
| 34 | + |
31 | 35 | for platform in PLATFORMS: |
32 | 36 | hass.async_create_task( |
33 | 37 | hass.config_entries.async_forward_entry_setup(entry, platform) |
34 | 38 | ) |
35 | 39 | return True |
36 | 40 |
|
37 | 41 |
|
| 42 | +async def update_listener(hass, entry): |
| 43 | + """Handle options update.""" |
| 44 | + speedport: Speedport = hass.data[DOMAIN][entry.entry_id] |
| 45 | + speedport.set_pause_time(entry.options.get("pause_time", 5)) |
| 46 | + |
| 47 | + |
38 | 48 | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: |
39 | 49 | """Unload a config entry.""" |
40 | 50 | if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): |
|
0 commit comments