* Rewrite to import from platform setup * Add config flow for import * Implement reload * Update sensor tests * Add config flow tests * Remove some code * Fix pylint issue * Remove update options code * Add platform import test * Remove infinite while loop * Move async_setup_platform * Check for unload_ok * Remove commented out test code * Implement function to check on host/port already existing Co-authored-by: Chris Talkington <chris@talkingtontech.com> * Implement new method in import * Update tests * Fix test setup platform * Add string * Patch setup_platform * Add block till done to patch block Co-authored-by: Chris Talkington <chris@talkingtontech.com>
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
"""The dsmr component."""
|
|
import asyncio
|
|
from asyncio import CancelledError
|
|
import logging
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .const import DATA_TASK, DOMAIN, PLATFORMS
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def async_setup(hass, config: dict):
|
|
"""Set up the DSMR platform."""
|
|
return True
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
"""Set up DSMR from a config entry."""
|
|
hass.data.setdefault(DOMAIN, {})
|
|
hass.data[DOMAIN][entry.entry_id] = {}
|
|
|
|
for platform in PLATFORMS:
|
|
hass.async_create_task(
|
|
hass.config_entries.async_forward_entry_setup(entry, platform)
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
"""Unload a config entry."""
|
|
task = hass.data[DOMAIN][entry.entry_id][DATA_TASK]
|
|
|
|
# Cancel the reconnect task
|
|
task.cancel()
|
|
try:
|
|
await task
|
|
except CancelledError:
|
|
pass
|
|
|
|
unload_ok = all(
|
|
await asyncio.gather(
|
|
*[
|
|
hass.config_entries.async_forward_entry_unload(entry, component)
|
|
for component in PLATFORMS
|
|
]
|
|
)
|
|
)
|
|
if unload_ok:
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|