-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding config flow setup, convert async to sync
- Loading branch information
Showing
8 changed files
with
179 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,43 @@ | ||
"""Example integration.""" | ||
""" Integration for Aigues de Barcelona. """ | ||
|
||
import asyncio | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.typing import ConfigType | ||
from __future__ import annotations | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import ( | ||
CONF_NAME, | ||
CONF_USERNAME, | ||
CONF_PASSWORD, | ||
CONF_SCAN_INTERVAL | ||
Platform, | ||
) | ||
import logging | ||
import voluptuous as vol | ||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.core import HomeAssistant, ServiceCall | ||
from homeassistant.exceptions import ConfigEntryNotReady | ||
from homeassistant.helpers import config_validation as cv | ||
from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
|
||
from .const import DOMAIN, DEFAULT_SCAN_PERIOD | ||
from .const import DOMAIN | ||
from .api import AiguesApiClient | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
PLATFORMS = [Platform.SENSOR] | ||
|
||
ACCOUNT_CONFIG_SCHEMA = vol.Schema( | ||
{ | ||
vol.Required(CONF_NAME): cv.string, | ||
vol.Required(CONF_PASSWORD): cv.string, | ||
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_PERIOD): cv.time_period, | ||
} | ||
) | ||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
|
||
api = AiguesApiClient(entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD]) | ||
|
||
try: | ||
await hass.async_add_executor_job(api.login) | ||
except: | ||
raise ConfigEntryNotReady | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
||
return True | ||
|
||
async def async_setup(hass: HomeAssistant, config: ConfigType, discovery_info=None) -> bool: | ||
""" Set up the domain. """ | ||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
if unload_ok: | ||
hass.data[DOMAIN].pop(entry.entry_id) | ||
if not hass.data[DOMAIN]: | ||
del hass.data[DOMAIN] | ||
|
||
if DOMAIN not in config: | ||
_LOGGER.debug( | ||
"Nothing to import from configuration.yaml, loading from Integrations", | ||
) | ||
return True | ||
return unload_ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
""" Constants definition """ | ||
from datetime import timedelta | ||
|
||
DOMAIN = "aigues_barcelona" | ||
|
||
DEFAULT_SCAN_PERIOD = timedelta(hours=1) | ||
DEFAULT_SCAN_PERIOD = 3600 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.