1 """Support for Plum Lightpad devices."""
5 from aiohttp
import ContentTypeError
6 from requests.exceptions
import ConnectTimeout, HTTPError
12 EVENT_HOMEASSISTANT_STOP,
18 from .const
import DOMAIN
19 from .utils
import load_plum
21 _LOGGER = logging.getLogger(__name__)
23 PLATFORMS = [Platform.LIGHT]
27 """Set up Plum Lightpad from a config entry."""
28 _LOGGER.debug(
"Setting up config entry with ID = %s", entry.unique_id)
30 username = entry.data[CONF_USERNAME]
31 password = entry.data[CONF_PASSWORD]
34 plum = await
load_plum(username, password, hass)
35 except ContentTypeError
as ex:
36 _LOGGER.error(
"Unable to authenticate to Plum cloud: %s", ex)
38 except (ConnectTimeout, HTTPError)
as ex:
39 _LOGGER.error(
"Unable to connect to Plum cloud: %s", ex)
40 raise ConfigEntryNotReady
from ex
42 hass.data.setdefault(DOMAIN, {})
43 hass.data[DOMAIN][entry.entry_id] = plum
45 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
48 """Clean up resources."""
51 entry.async_on_unload(hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, cleanup))
Plum load_plum(str username, str password, HomeAssistant hass)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)