* Linky: setup ConfigFlow * async_track_time_interval * Review from @MartinHjelmare 1 * Review from @MartinHjelmare 2 * Review from @MartinHjelmare 3 * Review from @MartinHjelmare 4 * black --fast homeassistant tests * Bump pylinky to 0.4.0 and add error user feedback * Fix .coveragerc * Linky platform moved to integration in config.yml and with multiple accounts * Remove useless logs * Review from @MartinHjelmare 5 * Add config flow tests * Add config flow tests : login + fetch on failed
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
"""The linky component."""
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
from homeassistant.const import CONF_PASSWORD, CONF_TIMEOUT, CONF_USERNAME
|
|
import homeassistant.helpers.config_validation as cv
|
|
from homeassistant.helpers.typing import HomeAssistantType
|
|
|
|
from .const import DEFAULT_TIMEOUT, DOMAIN
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
ACCOUNT_SCHEMA = vol.Schema(
|
|
{
|
|
vol.Required(CONF_USERNAME): cv.string,
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
|
|
}
|
|
)
|
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
{DOMAIN: vol.Schema(vol.All(cv.ensure_list, [ACCOUNT_SCHEMA]))},
|
|
extra=vol.ALLOW_EXTRA,
|
|
)
|
|
|
|
|
|
async def async_setup(hass, config):
|
|
"""Set up Linky sensors from legacy config file."""
|
|
|
|
conf = config.get(DOMAIN)
|
|
if conf is None:
|
|
return True
|
|
|
|
for linky_account_conf in conf:
|
|
hass.async_create_task(
|
|
hass.config_entries.flow.async_init(
|
|
DOMAIN,
|
|
context={"source": SOURCE_IMPORT},
|
|
data=linky_account_conf.copy(),
|
|
)
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
|
"""Set up Linky sensors."""
|
|
|
|
hass.async_create_task(
|
|
hass.config_entries.async_forward_entry_setup(entry, "sensor")
|
|
)
|
|
|
|
return True
|